[−][src]Trait sml::FromSmall
Types that implement the FromSmall
trait can be constructed from a small-formatted string.
Required methods
fn from_small(slice: &SmallRef) -> Result<Self, SmallError> where
Self: Sized,
Self: Sized,
The from_small()
function describes how to create a data-structure from the internal
components of the input String
. It maps a selection from the original input String
to
Self
. For example,
use small::{SmallRef, FromSmall, SmallError}; #[derive(Debug)] struct Hobbit { name: String, age: u32, friends: Vec<Hobbit>, bicycle: Option<String>, } impl FromSmall for Hobbit { fn from_small(small: Small) -> Result<Self, SmallError> { Ok(Self { name: String::sml(&[small], "hobbit::name")?, age: u32::sml(&[small], "hobbit::age")?, friends: Vec::<Hobbit>::sml(&[small], "hobbit::friends::hobbit")?, bicycle: Option::<String>::sml(&[small], "hobbit::bicycle")?, }) } } fn main() { let s = r#" hobbit: name: "Frodo Baggins" age: "98" friends: hobbit: name: "Bilbo Baggins" age: "176" hobbit: name: "Samwise Gamgee" age: "66""#; let frodo = Hobbit::from_str_debug(s); }
Provided methods
fn sml(small: &SmallRef, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
Self: Sized,
Applies a keypath to Small
and returns a Vec
of Small
s. For example applying
"hobbit::name"
to
hobbit:
name: "Frodo Baggins"
age: "98"
friends:
hobbit:
name: "Bilbo Baggins"
age: "176"
hobbit:
name: "Samwise Gamgee"
age: "66""#;
returns a Vec
with one Small
element,
name: "Frodo Baggins"
Applying "hobbit::name::friends"
to the original string returns a Vec
with two Small
elements which represent
hobbit:
name: "Bilbo Baggins"
age: "176"
and
hobbit:
name: "Samwise Gamgee"
age: "66""#;
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
Self: Sized,
Converts a String
into Self
.
fn from_str_debug(s: &str) -> Self where
Self: Sized,
Self: Sized,
Converts a String
into Self
. This function is designed to give helpful error messages
for debugging.
fn to_sml(small: &SmallRef) -> String
Implementations on Foreign Types
impl FromSmall for String
[src]
Converts a Vec
of one Small
element to a String
.
fn from_small(small: &SmallRef) -> Result<Self, SmallError>
[src]
fn sml(small: &SmallRef, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str_debug(s: &str) -> Self where
Self: Sized,
[src]
Self: Sized,
fn to_sml(small: &SmallRef) -> String
[src]
impl FromSmall for u32
[src]
Converts a Vec
with one Small
element to a u32
.
fn from_small(small: &SmallRef) -> Result<Self, SmallError>
[src]
fn sml(small: &SmallRef, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str_debug(s: &str) -> Self where
Self: Sized,
[src]
Self: Sized,
fn to_sml(small: &SmallRef) -> String
[src]
impl FromSmall for usize
[src]
Converts a Vec
with one Small
element to a usize
.
fn from_small(small: &SmallRef) -> Result<Self, SmallError>
[src]
fn sml(small: &SmallRef, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str_debug(s: &str) -> Self where
Self: Sized,
[src]
Self: Sized,
fn to_sml(small: &SmallRef) -> String
[src]
impl FromSmall for f32
[src]
Converts a Vec
with one Small
element to a f32
.
fn from_small(small: &SmallRef) -> Result<Self, SmallError>
[src]
fn sml(small: &SmallRef, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str_debug(s: &str) -> Self where
Self: Sized,
[src]
Self: Sized,
fn to_sml(small: &SmallRef) -> String
[src]
impl FromSmall for bool
[src]
Converts a Vec
with one Small
element to a bool
.
fn from_small(small: &SmallRef) -> Result<Self, SmallError>
[src]
fn sml(small: &SmallRef, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str_debug(s: &str) -> Self where
Self: Sized,
[src]
Self: Sized,
fn to_sml(small: &SmallRef) -> String
[src]
impl<T> FromSmall for Option<T> where
T: FromSmall,
[src]
T: FromSmall,
Converts a Vec
with either one or no Small
elements to an Option<T>
.
fn from_small(small: &SmallRef) -> Result<Self, SmallError>
[src]
fn sml(small: &SmallRef, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str_debug(s: &str) -> Self where
Self: Sized,
[src]
Self: Sized,
fn to_sml(small: &SmallRef) -> String
[src]
impl<T> FromSmall for Vec<T> where
T: FromSmall,
[src]
T: FromSmall,
Converts a Vec
of Small
elements to a Vec<T>
.
fn from_small(sr: &SmallRef) -> Result<Self, SmallError>
[src]
fn sml(small: &SmallRef, key_path: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str(s: &str) -> Result<Self, SmallError> where
Self: Sized,
[src]
Self: Sized,
fn from_str_debug(s: &str) -> Self where
Self: Sized,
[src]
Self: Sized,