How do you read a YAML file in Rust?
up vote
-3
down vote
favorite
I've poked the serde-yaml and yaml-rust crates a bit, but I haven't seen any examples.
rust yaml
add a comment |
up vote
-3
down vote
favorite
I've poked the serde-yaml and yaml-rust crates a bit, but I haven't seen any examples.
rust yaml
add a comment |
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
I've poked the serde-yaml and yaml-rust crates a bit, but I haven't seen any examples.
rust yaml
I've poked the serde-yaml and yaml-rust crates a bit, but I haven't seen any examples.
rust yaml
rust yaml
edited Nov 10 at 22:15
Shepmaster
143k11268400
143k11268400
asked Nov 10 at 21:56
ralston3
496414
496414
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
serde-yaml's documentation has the following 4 functions:
from_reader— Deserialize an instance of typeTfrom an IO stream of YAML.
from_slice— Deserialize an instance of typeTfrom bytes of YAML text.
from_str— Deserialize an instance of typeTfrom a string of YAML text.
from_value— Interpret aserde_yaml::Valueas an instance of typeT.
Using from_reader as an example:
extern crate serde_yaml;
fn main() -> Result<(), Box<std::error::Error>> {
let f = std::fs::File::open("something.yaml")?;
let d: String = serde_yaml::from_reader(f)?;
println!("Read YAML string: {}", d);
Ok(())
}
You can deserialize into the looser-typed Value if you don't know your format, but be sure to read the Serde guide for full details of how to do type-directed serialization and deserialization.
See also:
- How do I parse a JSON File?
- Deserializing TOML into vector of enum with values
In general, using any Serde format is pretty much the same as all the rest.
add a comment |
up vote
0
down vote
A YAML file is a normal (text) file like any other you can read it using
the example in the Rust documentation. In particular using File::open(filename) and doing .read_to_string() on the result of the former.
yaml-rust and serde-yaml are for parsing and loading YAML files, and since your question doesn't indicate that you want to do that, but only want to read the file, there is no need to use those libraries.
1
What's the de-facto way of reading and writing files in Rust 1.x? — namelyfs::read_to_stringis shorter.
– Shepmaster
Nov 10 at 22:41
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
serde-yaml's documentation has the following 4 functions:
from_reader— Deserialize an instance of typeTfrom an IO stream of YAML.
from_slice— Deserialize an instance of typeTfrom bytes of YAML text.
from_str— Deserialize an instance of typeTfrom a string of YAML text.
from_value— Interpret aserde_yaml::Valueas an instance of typeT.
Using from_reader as an example:
extern crate serde_yaml;
fn main() -> Result<(), Box<std::error::Error>> {
let f = std::fs::File::open("something.yaml")?;
let d: String = serde_yaml::from_reader(f)?;
println!("Read YAML string: {}", d);
Ok(())
}
You can deserialize into the looser-typed Value if you don't know your format, but be sure to read the Serde guide for full details of how to do type-directed serialization and deserialization.
See also:
- How do I parse a JSON File?
- Deserializing TOML into vector of enum with values
In general, using any Serde format is pretty much the same as all the rest.
add a comment |
up vote
2
down vote
accepted
serde-yaml's documentation has the following 4 functions:
from_reader— Deserialize an instance of typeTfrom an IO stream of YAML.
from_slice— Deserialize an instance of typeTfrom bytes of YAML text.
from_str— Deserialize an instance of typeTfrom a string of YAML text.
from_value— Interpret aserde_yaml::Valueas an instance of typeT.
Using from_reader as an example:
extern crate serde_yaml;
fn main() -> Result<(), Box<std::error::Error>> {
let f = std::fs::File::open("something.yaml")?;
let d: String = serde_yaml::from_reader(f)?;
println!("Read YAML string: {}", d);
Ok(())
}
You can deserialize into the looser-typed Value if you don't know your format, but be sure to read the Serde guide for full details of how to do type-directed serialization and deserialization.
See also:
- How do I parse a JSON File?
- Deserializing TOML into vector of enum with values
In general, using any Serde format is pretty much the same as all the rest.
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
serde-yaml's documentation has the following 4 functions:
from_reader— Deserialize an instance of typeTfrom an IO stream of YAML.
from_slice— Deserialize an instance of typeTfrom bytes of YAML text.
from_str— Deserialize an instance of typeTfrom a string of YAML text.
from_value— Interpret aserde_yaml::Valueas an instance of typeT.
Using from_reader as an example:
extern crate serde_yaml;
fn main() -> Result<(), Box<std::error::Error>> {
let f = std::fs::File::open("something.yaml")?;
let d: String = serde_yaml::from_reader(f)?;
println!("Read YAML string: {}", d);
Ok(())
}
You can deserialize into the looser-typed Value if you don't know your format, but be sure to read the Serde guide for full details of how to do type-directed serialization and deserialization.
See also:
- How do I parse a JSON File?
- Deserializing TOML into vector of enum with values
In general, using any Serde format is pretty much the same as all the rest.
serde-yaml's documentation has the following 4 functions:
from_reader— Deserialize an instance of typeTfrom an IO stream of YAML.
from_slice— Deserialize an instance of typeTfrom bytes of YAML text.
from_str— Deserialize an instance of typeTfrom a string of YAML text.
from_value— Interpret aserde_yaml::Valueas an instance of typeT.
Using from_reader as an example:
extern crate serde_yaml;
fn main() -> Result<(), Box<std::error::Error>> {
let f = std::fs::File::open("something.yaml")?;
let d: String = serde_yaml::from_reader(f)?;
println!("Read YAML string: {}", d);
Ok(())
}
You can deserialize into the looser-typed Value if you don't know your format, but be sure to read the Serde guide for full details of how to do type-directed serialization and deserialization.
See also:
- How do I parse a JSON File?
- Deserializing TOML into vector of enum with values
In general, using any Serde format is pretty much the same as all the rest.
answered Nov 10 at 22:15
Shepmaster
143k11268400
143k11268400
add a comment |
add a comment |
up vote
0
down vote
A YAML file is a normal (text) file like any other you can read it using
the example in the Rust documentation. In particular using File::open(filename) and doing .read_to_string() on the result of the former.
yaml-rust and serde-yaml are for parsing and loading YAML files, and since your question doesn't indicate that you want to do that, but only want to read the file, there is no need to use those libraries.
1
What's the de-facto way of reading and writing files in Rust 1.x? — namelyfs::read_to_stringis shorter.
– Shepmaster
Nov 10 at 22:41
add a comment |
up vote
0
down vote
A YAML file is a normal (text) file like any other you can read it using
the example in the Rust documentation. In particular using File::open(filename) and doing .read_to_string() on the result of the former.
yaml-rust and serde-yaml are for parsing and loading YAML files, and since your question doesn't indicate that you want to do that, but only want to read the file, there is no need to use those libraries.
1
What's the de-facto way of reading and writing files in Rust 1.x? — namelyfs::read_to_stringis shorter.
– Shepmaster
Nov 10 at 22:41
add a comment |
up vote
0
down vote
up vote
0
down vote
A YAML file is a normal (text) file like any other you can read it using
the example in the Rust documentation. In particular using File::open(filename) and doing .read_to_string() on the result of the former.
yaml-rust and serde-yaml are for parsing and loading YAML files, and since your question doesn't indicate that you want to do that, but only want to read the file, there is no need to use those libraries.
A YAML file is a normal (text) file like any other you can read it using
the example in the Rust documentation. In particular using File::open(filename) and doing .read_to_string() on the result of the former.
yaml-rust and serde-yaml are for parsing and loading YAML files, and since your question doesn't indicate that you want to do that, but only want to read the file, there is no need to use those libraries.
edited Nov 10 at 22:40
Shepmaster
143k11268400
143k11268400
answered Nov 10 at 22:26
Anthon
27.8k1691142
27.8k1691142
1
What's the de-facto way of reading and writing files in Rust 1.x? — namelyfs::read_to_stringis shorter.
– Shepmaster
Nov 10 at 22:41
add a comment |
1
What's the de-facto way of reading and writing files in Rust 1.x? — namelyfs::read_to_stringis shorter.
– Shepmaster
Nov 10 at 22:41
1
1
What's the de-facto way of reading and writing files in Rust 1.x? — namely
fs::read_to_string is shorter.– Shepmaster
Nov 10 at 22:41
What's the de-facto way of reading and writing files in Rust 1.x? — namely
fs::read_to_string is shorter.– Shepmaster
Nov 10 at 22:41
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243795%2fhow-do-you-read-a-yaml-file-in-rust%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown