-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
58 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,41 +50,46 @@ | |
//! In particular, the [`output::Output`] and [`input::Input`] traits can be derived | ||
//! automatically for structs with named fields. | ||
//! | ||
//! ``` | ||
//! # use hugr_sexpr::input::Input; | ||
//! # use hugr_sexpr::output::Output; | ||
//! #[derive(Debug, PartialEq, Input, Output)] | ||
//! pub struct Person { | ||
//! name: String, | ||
//! #[sexpr(required)] | ||
//! company: String, | ||
//! #[sexpr(optional)] | ||
//! birthday: Option<String>, | ||
//! #[sexpr(repeated)] | ||
//! #[sexpr(rename = "email")] | ||
//! email_addresses: Vec<String>, | ||
//! } | ||
//! | ||
//! let person = Person { | ||
//! name: "John Doe".to_string(), | ||
//! company: "ACME".to_string(), | ||
//! birthday: None, | ||
//! email_addresses: vec![ | ||
//! "[email protected]".to_string(), | ||
//! "[email protected]".to_string() | ||
//! ], | ||
//! }; | ||
//! | ||
//! let sexpr = r#" | ||
//! "John Doe" | ||
//! (company "ACME") | ||
//! (email "[email protected]") | ||
//! (email "[email protected]") | ||
//! "#; | ||
//! | ||
//! let imported = hugr_sexpr::from_str::<Person>(sexpr).unwrap(); | ||
//! assert_eq!(imported, person); | ||
//! ``` | ||
#[cfg_attr( | ||
feature = "derive", | ||
doc = r##" | ||
``` | ||
# use hugr_sexpr::input::Input; | ||
# use hugr_sexpr::output::Output; | ||
#[derive(Debug, PartialEq, Input, Output)] | ||
pub struct Person { | ||
name: String, | ||
#[sexpr(required)] | ||
company: String, | ||
#[sexpr(optional)] | ||
birthday: Option<String>, | ||
#[sexpr(repeated)] | ||
#[sexpr(rename = "email")] | ||
email_addresses: Vec<String>, | ||
} | ||
let person = Person { | ||
name: "John Doe".to_string(), | ||
company: "ACME".to_string(), | ||
birthday: None, | ||
email_addresses: vec![ | ||
"[email protected]".to_string(), | ||
"[email protected]".to_string() | ||
], | ||
}; | ||
let sexpr = r#" | ||
"John Doe" | ||
(company "ACME") | ||
(email "[email protected]") | ||
(email "[email protected]") | ||
"#; | ||
let imported = hugr_sexpr::from_str::<Person>(sexpr).unwrap(); | ||
assert_eq!(imported, person); | ||
``` | ||
"## | ||
)] | ||
use ordered_float::OrderedFloat; | ||
use smol_str::SmolStr; | ||
use std::fmt::Display; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters