Skip to main content

PublicConfig

Struct PublicConfig 

Source
pub struct PublicConfig { /* private fields */ }
Expand description

The effective configuration with every secret-reference field removed.

Entries are held in byte order of their dotted paths. Serialises as a JSON object whose first key is schema_version, followed by each dotted path mapped to its value, so a client can recompute PublicConfig::hash from the JSON alone.

§Examples

use stratum_node_config::{schema, ConfigDocument, Value};

let doc = ConfigDocument::parse(&schema().seed_text())?;
let public = doc.public_config();
assert_eq!(public.get("listen.address"), Some(&Value::from("127.0.0.1:7460")));
assert_eq!(public.get("secrets.pod_admin_key_ref"), None);

Implementations§

Source§

impl PublicConfig

Source

pub fn get(&self, path: &str) -> Option<&Value>

Returns the value at a dotted path, or None for secret-reference fields and paths not in the schema.

Source

pub fn iter(&self) -> PublicIter<'_> ⓘ

Iterates over (path, value) pairs in byte order of the path.

Source

pub fn len(&self) -> usize

Returns the number of fields in the public view.

Source

pub fn is_empty(&self) -> bool

Returns true if the public view has no fields.

Source

pub fn canonical_text(&self) -> String

Returns the canonical TOML text the hash is computed over.

The text is valid TOML. Its first line is schema_version = <SCHEMA_VERSION>. Every public field follows, one per line, as <dotted.path> = <value>\n, in byte order of the path. Values use a fixed encoding that does not depend on any TOML library: booleans are true/false; integers are decimal with a leading - when negative; strings are double-quoted with " and \ backslash-escaped and every ASCII control character written as \uXXXX in upper-case hex, all other characters as literal UTF-8; lists are [, the encoded strings separated by ", ", then ]. Because no encoded value contains a raw newline and every string is delimited and escaped, distinct configurations give distinct texts.

§Examples
use stratum_node_config::{schema, ConfigDocument};

let doc = ConfigDocument::parse(&schema().seed_text())?;
let text = doc.public_config().canonical_text();
assert!(text.starts_with("schema_version = 1\nbackup.age_recipients = []\n"));
Source

pub fn hash(&self) -> PublicHash

Returns the public-configuration hash.

The hash is SHA-256("stratum.public-config.v1\n" ‖ canonical_text), where the prefix carries PUBLIC_HASH_VERSION and canonical_text is PublicConfig::canonical_text encoded as UTF-8. Changing a secret reference never changes it; changing any other field’s effective value, the schema version, or a default that a document relies on always does.

Trait Implementations§

Source§

impl Clone for PublicConfig

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PublicConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for PublicConfig

Source§

impl<'a> IntoIterator for &'a PublicConfig

Source§

type Item = (&'static str, &'a Value)

The type of the elements being iterated over.
Source§

type IntoIter = PublicIter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for PublicConfig

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for PublicConfig

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for PublicConfig

Auto Trait Implementations§

§

impl Forget for PublicConfig

§

impl Freeze for PublicConfig
where *const u8 is !null: Freeze, PhantomData<(&'static str, Value)>: Freeze,

§

impl Move for PublicConfig

§

impl RefUnwindSafe for PublicConfig

§

impl Send for PublicConfig
where RawVecInner: Send, &'static str: Send,

§

impl Sync for PublicConfig
where RawVecInner: Sync,

§

impl Unpin for PublicConfig
where *const u8 is !null: Unpin, &'static str: Unpin,

§

impl UnsafeUnpin for PublicConfig
where *const u8 is !null: UnsafeUnpin, PhantomData<(&'static str, Value)>: UnsafeUnpin,

§

impl UnwindSafe for PublicConfig
where RawVecInner: UnwindSafe, &'static str: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.