Skip to content

Commit

Permalink
Merge pull request #1082 from dtolnay/fromdoc
Browse files Browse the repository at this point in the history
Improve Value From and FromIterator docs
  • Loading branch information
dtolnay committed Oct 30, 2023
2 parents a8e6f75 + 0f072fa commit 1454eac
Showing 1 changed file with 15 additions and 13 deletions.
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

0 comments on commit 1454eac

Please sign in to comment.