pub struct ConfigDocument { /* private fields */ }Expand description
A validated stratum.toml document: its exact text plus the effective
configuration with defaults filled in.
The only way to obtain one is ConfigDocument::parse (or
Preview::document), so holding a
ConfigDocument proves the text passed every rule in the schema.
§Examples
use stratum_node_config::{ConfigDocument, Value};
let doc = ConfigDocument::parse(
"schema_version = 1\n\n[node]\nname = \"alpha\"\n",
)?;
assert_eq!(doc.config().node_name(), "alpha");
// Omitted fields take their defaults.
assert_eq!(doc.value("limits.max_outstanding_challenges"), Some(&Value::Integer(16)));Implementations§
Source§impl ConfigDocument
impl ConfigDocument
Sourcepub fn parse(text: &str) -> Result<Self, ValidationErrors>
pub fn parse(text: &str) -> Result<Self, ValidationErrors>
Parses and validates stratum.toml text.
§Errors
Returns every problem found, not just the first: a TOML syntax error
(reported alone, since nothing else can be checked), a missing or
unsupported schema_version, unknown keys and tables, values of the
wrong type, integers out of range, values that break a field’s rule,
and cross-field conflicts. Text longer than MAX_DOCUMENT_BYTES is
refused unparsed with a single ValidationErrorKind::TooLarge error.
§Examples
use stratum_node_config::{ConfigDocument, ValidationErrorKind};
let text = "schema_version = 1\n[limits]\nmax_body_bytes = 1\ncolour = \"red\"\n";
let errors = ConfigDocument::parse(text).err().ok_or("expected errors")?;
let kinds: Vec<_> = errors.iter().map(|e| (e.path(), e.kind())).collect();
assert_eq!(kinds, [
(Some("limits.colour"), ValidationErrorKind::UnknownKey),
(Some("limits.max_body_bytes"), ValidationErrorKind::OutOfRange),
]);Sourcepub fn value(&self, path: &str) -> Option<&Value>
pub fn value(&self, path: &str) -> Option<&Value>
Returns the effective value of a field, with its default filled in
when the document omits it, or None for a path not in the schema.
Sourcepub fn public_config(&self) -> PublicConfig
pub fn public_config(&self) -> PublicConfig
Returns the effective configuration without its secret-reference fields, safe to show to anyone who may see the node’s status.
Sourcepub fn public_hash(&self) -> PublicHash
pub fn public_hash(&self) -> PublicHash
Returns the SHA-256 hash of the public configuration, as defined on
PublicConfig::hash.
Trait Implementations§
Source§impl Clone for ConfigDocument
impl Clone for ConfigDocument
Source§impl Debug for ConfigDocument
Redacted: shows the typed configuration (whose secret reference is
itself redacted) and the public hash, never the raw text.
impl Debug for ConfigDocument
Redacted: shows the typed configuration (whose secret reference is itself redacted) and the public hash, never the raw text.
impl Eq for ConfigDocument
Source§impl PartialEq for ConfigDocument
impl PartialEq for ConfigDocument
impl StructuralPartialEq for ConfigDocument
Auto Trait Implementations§
impl Forget for ConfigDocument
impl Freeze for ConfigDocumentwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<Value>: Freeze,
PhantomData<String>: Freeze,
impl Move for ConfigDocument
impl RefUnwindSafe for ConfigDocument
impl Send for ConfigDocumentwhere
RawVecInner: Send,
impl Sync for ConfigDocumentwhere
RawVecInner: Sync,
impl Unpin for ConfigDocument
impl UnsafeUnpin for ConfigDocumentwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<Value>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
impl UnwindSafe for ConfigDocumentwhere
RawVecInner: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.