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.










share|improve this question



























    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.










    share|improve this question

























      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.










      share|improve this question















      I've poked the serde-yaml and yaml-rust crates a bit, but I haven't seen any examples.







      rust yaml






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 22:15









      Shepmaster

      146k11281413




      146k11281413










      asked Nov 10 at 21:56









      ralston3

      508415




      508415






















          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 type T from an IO stream of YAML.


          • from_slice — Deserialize an instance of type T from bytes of YAML text.


          • from_str — Deserialize an instance of type T from a string of YAML text.


          • from_value — Interpret a serde_yaml::Value as an instance of type T.

          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.






          share|improve this answer



























            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.






            share|improve this answer


















            • 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










            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            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

























            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 type T from an IO stream of YAML.


            • from_slice — Deserialize an instance of type T from bytes of YAML text.


            • from_str — Deserialize an instance of type T from a string of YAML text.


            • from_value — Interpret a serde_yaml::Value as an instance of type T.

            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.






            share|improve this answer
























              up vote
              2
              down vote



              accepted










              serde-yaml's documentation has the following 4 functions:




              • from_reader — Deserialize an instance of type T from an IO stream of YAML.


              • from_slice — Deserialize an instance of type T from bytes of YAML text.


              • from_str — Deserialize an instance of type T from a string of YAML text.


              • from_value — Interpret a serde_yaml::Value as an instance of type T.

              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.






              share|improve this answer






















                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 type T from an IO stream of YAML.


                • from_slice — Deserialize an instance of type T from bytes of YAML text.


                • from_str — Deserialize an instance of type T from a string of YAML text.


                • from_value — Interpret a serde_yaml::Value as an instance of type T.

                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.






                share|improve this answer












                serde-yaml's documentation has the following 4 functions:




                • from_reader — Deserialize an instance of type T from an IO stream of YAML.


                • from_slice — Deserialize an instance of type T from bytes of YAML text.


                • from_str — Deserialize an instance of type T from a string of YAML text.


                • from_value — Interpret a serde_yaml::Value as an instance of type T.

                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 22:15









                Shepmaster

                146k11281413




                146k11281413






















                    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.






                    share|improve this answer


















                    • 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














                    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.






                    share|improve this answer


















                    • 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












                    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.






                    share|improve this answer














                    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.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 10 at 22:40









                    Shepmaster

                    146k11281413




                    146k11281413










                    answered Nov 10 at 22:26









                    Anthon

                    28.2k1693144




                    28.2k1693144







                    • 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












                    • 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







                    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

















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Darth Vader #20

                    Ondo