22 lines
9.2 KiB
HTML
22 lines
9.2 KiB
HTML
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="YAML 1.2 implementation in pure Rust."><meta name="keywords" content="rust, rustlang, rust-lang, yaml_rust"><title>yaml_rust - Rust</title><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Regular.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../FiraSans-Medium.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Regular.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceSerif4-Bold.ttf.woff2"><link rel="preload" as="font" type="font/woff2" crossorigin href="../SourceCodePro-Semibold.ttf.woff2"><link rel="stylesheet" type="text/css" href="../normalize.css"><link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../ayu.css" disabled><link rel="stylesheet" type="text/css" href="../dark.css" disabled><link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle"><script id="default-settings" ></script><script src="../storage.js"></script><script defer src="../crates.js"></script><script defer src="../main.js"></script><noscript><link rel="stylesheet" href="../noscript.css"></noscript><link rel="alternate icon" type="image/png" href="../favicon-16x16.png"><link rel="alternate icon" type="image/png" href="../favicon-32x32.png"><link rel="icon" type="image/svg+xml" href="../favicon.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle">☰</button><a class="sidebar-logo" href="../yaml_rust/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"></h2></nav><nav class="sidebar"><a class="sidebar-logo" href="../yaml_rust/index.html"><div class="logo-container"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></div></a><h2 class="location"><a href="#">Crate yaml_rust</a></h2><div class="sidebar-elems"><div class="block"><ul><li class="version">Version 0.4.5</li><li><a id="all-types" href="all.html">All Items</a></li></ul></div><section><div class="block"><ul><li><a href="#reexports">Re-exports</a></li><li><a href="#modules">Modules</a></li></ul></div></section></div></nav><main><div class="width-limiter"><div class="sub-container"><a class="sub-logo-container" href="../yaml_rust/index.html"><img class="rust-logo" src="../rust-logo.svg" alt="logo"></a><nav class="sub"><form class="search-form"><div class="search-container"><span></span><input class="search-input" name="search" autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"><div id="help-button" title="help" tabindex="-1"><button type="button">?</button></div><div id="settings-menu" tabindex="-1"><a href="../settings.html" title="settings"><img width="22" height="22" alt="Change settings" src="../wheel.svg"></a></div></div></form></nav></div><section id="main-content" class="content"><div class="main-heading"><h1 class="fqn"><span class="in-band">Crate <a class="mod" href="#">yaml_rust</a><button id="copy-path" onclick="copy_path(this)" title="Copy item path to clipboard"><img src="../clipboard.svg" width="19" height="18" alt="Copy item path"></button></span></h1><span class="out-of-band"><a class="srclink" href="../src/yaml_rust/lib.rs.html#4-121">source</a> · <a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">[<span class="inner">−</span>]</a></span></div><details class="rustdoc-toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>YAML 1.2 implementation in pure Rust.</p>
|
||
<h2 id="usage"><a href="#usage">Usage</a></h2>
|
||
<p>This crate is <a href="https://github.com/chyh1990/yaml-rust">on github</a> and can be
|
||
used by adding <code>yaml-rust</code> to the dependencies in your project’s <code>Cargo.toml</code>.</p>
|
||
<div class="example-wrap"><pre class="language-toml"><code>[dependencies.yaml-rust]
|
||
git = "https://github.com/chyh1990/yaml-rust.git"</code></pre></div>
|
||
<p>And this in your crate root:</p>
|
||
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">extern</span> <span class="kw">crate</span> <span class="ident">yaml_rust</span>;</code></pre></div>
|
||
<p>Parse a string into <code>Vec<Yaml></code> and then serialize it as a YAML string.</p>
|
||
<h2 id="examples"><a href="#examples">Examples</a></h2>
|
||
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use</span> <span class="ident">yaml_rust</span>::{<span class="ident">YamlLoader</span>, <span class="ident">YamlEmitter</span>};
|
||
|
||
<span class="kw">let</span> <span class="ident">docs</span> <span class="op">=</span> <span class="ident">YamlLoader::load_from_str</span>(<span class="string">"[1, 2, 3]"</span>).<span class="ident">unwrap</span>();
|
||
<span class="kw">let</span> <span class="ident">doc</span> <span class="op">=</span> <span class="kw-2">&</span><span class="ident">docs</span>[<span class="number">0</span>]; <span class="comment">// select the first document</span>
|
||
<span class="macro">assert_eq!</span>(<span class="ident">doc</span>[<span class="number">0</span>].<span class="ident">as_i64</span>().<span class="ident">unwrap</span>(), <span class="number">1</span>); <span class="comment">// access elements by index</span>
|
||
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">out_str</span> <span class="op">=</span> <span class="ident">String::new</span>();
|
||
<span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">emitter</span> <span class="op">=</span> <span class="ident">YamlEmitter::new</span>(<span class="kw-2">&mut</span> <span class="ident">out_str</span>);
|
||
<span class="ident">emitter</span>.<span class="ident">dump</span>(<span class="ident">doc</span>).<span class="ident">unwrap</span>(); <span class="comment">// dump the YAML object to a String</span>
|
||
</code></pre></div>
|
||
</div></details><h2 id="reexports" class="small-section-header"><a href="#reexports">Re-exports</a></h2><div class="item-table"><div class="item-row"><div class="item-left import-item" id="reexport.EmitError"><code>pub use crate::emitter::<a class="enum" href="emitter/enum.EmitError.html" title="enum yaml_rust::emitter::EmitError">EmitError</a>;</code></div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left import-item" id="reexport.YamlEmitter"><code>pub use crate::emitter::<a class="struct" href="emitter/struct.YamlEmitter.html" title="struct yaml_rust::emitter::YamlEmitter">YamlEmitter</a>;</code></div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left import-item" id="reexport.Event"><code>pub use crate::parser::<a class="enum" href="parser/enum.Event.html" title="enum yaml_rust::parser::Event">Event</a>;</code></div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left import-item" id="reexport.ScanError"><code>pub use crate::scanner::<a class="struct" href="scanner/struct.ScanError.html" title="struct yaml_rust::scanner::ScanError">ScanError</a>;</code></div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left import-item" id="reexport.Yaml"><code>pub use crate::yaml::<a class="enum" href="yaml/enum.Yaml.html" title="enum yaml_rust::yaml::Yaml">Yaml</a>;</code></div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left import-item" id="reexport.YamlLoader"><code>pub use crate::yaml::<a class="struct" href="yaml/struct.YamlLoader.html" title="struct yaml_rust::yaml::YamlLoader">YamlLoader</a>;</code></div><div class="item-right docblock-short"></div></div></div><h2 id="modules" class="small-section-header"><a href="#modules">Modules</a></h2><div class="item-table"><div class="item-row"><div class="item-left module-item"><a class="mod" href="emitter/index.html" title="yaml_rust::emitter mod">emitter</a></div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="parser/index.html" title="yaml_rust::parser mod">parser</a></div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="scanner/index.html" title="yaml_rust::scanner mod">scanner</a></div><div class="item-right docblock-short"></div></div><div class="item-row"><div class="item-left module-item"><a class="mod" href="yaml/index.html" title="yaml_rust::yaml mod">yaml</a></div><div class="item-right docblock-short"></div></div></div></section></div></main><div id="rustdoc-vars" data-root-path="../" data-current-crate="yaml_rust" data-themes="ayu,dark,light" data-resource-suffix="" data-rustdoc-version="1.64.0 (a55dd71d5 2022-09-19)" ></div></body></html> |