Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Value From and FromIterator docs #1082

Merged
merged 1 commit into from Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 15 additions & 13 deletions src/value/from.rs
Expand Up @@ -28,7 +28,8 @@ from_integer! {
}

impl From<f32> for Value {
/// Convert 32-bit floating point number to `Value`
/// Convert 32-bit floating point number to `Value::Number`, or
/// `Value::Null` if infinite or NaN.
///
/// # Examples
///
Expand All @@ -44,7 +45,8 @@ impl From<f32> for Value {
}

impl From<f64> for Value {
/// Convert 64-bit floating point number to `Value`
/// Convert 64-bit floating point number to `Value::Number`, or
/// `Value::Null` if infinite or NaN.
///
/// # Examples
///
Expand All @@ -60,7 +62,7 @@ impl From<f64> for Value {
}

impl From<bool> for Value {
/// Convert boolean to `Value`
/// Convert boolean to `Value::Bool`.
///
/// # Examples
///
Expand All @@ -76,7 +78,7 @@ impl From<bool> for Value {
}

impl From<String> for Value {
/// Convert `String` to `Value`
/// Convert `String` to `Value::String`.
///
/// # Examples
///
Expand All @@ -92,7 +94,7 @@ impl From<String> for Value {
}

impl From<&str> for Value {
/// Convert string slice to `Value`
/// Convert string slice to `Value::String`.
///
/// # Examples
///
Expand All @@ -108,7 +110,7 @@ impl From<&str> for Value {
}

impl<'a> From<Cow<'a, str>> for Value {
/// Convert copy-on-write string to `Value`
/// Convert copy-on-write string to `Value::String`.
///
/// # Examples
///
Expand All @@ -133,7 +135,7 @@ impl<'a> From<Cow<'a, str>> for Value {
}

impl From<Number> for Value {
/// Convert `Number` to `Value`
/// Convert `Number` to `Value::Number`.
///
/// # Examples
///
Expand All @@ -149,7 +151,7 @@ impl From<Number> for Value {
}

impl From<Map<String, Value>> for Value {
/// Convert map (with string keys) to `Value`
/// Convert map (with string keys) to `Value::Object`.
///
/// # Examples
///
Expand All @@ -166,7 +168,7 @@ impl From<Map<String, Value>> for Value {
}

impl<T: Into<Value>> From<Vec<T>> for Value {
/// Convert a `Vec` to `Value`
/// Convert a `Vec` to `Value::Array`.
///
/// # Examples
///
Expand All @@ -182,7 +184,7 @@ impl<T: Into<Value>> From<Vec<T>> for Value {
}

impl<T: Clone + Into<Value>> From<&[T]> for Value {
/// Convert a slice to `Value`
/// Convert a slice to `Value::Array`.
///
/// # Examples
///
Expand All @@ -198,7 +200,7 @@ impl<T: Clone + Into<Value>> From<&[T]> for Value {
}

impl<T: Into<Value>> FromIterator<T> for Value {
/// Convert an iterable type to a `Value`
/// Create a `Value::Array` by collecting an iterator of array elements.
///
/// # Examples
///
Expand Down Expand Up @@ -228,7 +230,7 @@ impl<T: Into<Value>> FromIterator<T> for Value {
}

impl<K: Into<String>, V: Into<Value>> FromIterator<(K, V)> for Value {
/// Convert an iterable type to a `Value`
/// Create a `Value::Object` by collecting an iterator of key-value pairs.
///
/// # Examples
///
Expand All @@ -248,7 +250,7 @@ impl<K: Into<String>, V: Into<Value>> FromIterator<(K, V)> for Value {
}

impl From<()> for Value {
/// Convert `()` to `Value`
/// Convert `()` to `Value::Null`.
///
/// # Examples
///
Expand Down