pub struct NetworkStore { /* private fields */ }Expand description
Persistent store for network configurations.
Implementations§
Source§impl NetworkStore
impl NetworkStore
Sourcepub fn default_path() -> Result<Self>
pub fn default_path() -> Result<Self>
Create a store at the default location (~/.a3s/networks.json).
Sourcepub fn save(&self, networks: &HashMap<String, NetworkConfig>) -> Result<()>
pub fn save(&self, networks: &HashMap<String, NetworkConfig>) -> Result<()>
Save all networks to disk (atomic write).
Sourcepub fn with_write_lock<F, R, E>(&self, f: F) -> Result<R, E>
pub fn with_write_lock<F, R, E>(&self, f: F) -> Result<R, E>
Run f against the full networks map under the cross-process write
lock (load-fresh → mutate → save). Use this to make a
get-modify-update sequence atomic — e.g. allocate-an-IP-then-connect —
so concurrent boots cannot assign duplicate IPs/MACs or silently lose
each other’s endpoints. The map is saved only if f returns Ok.
The lock is held across the whole load/mutate/save; save is itself
lock-free, so there is no re-entrant flock (which would self-deadlock).
Sourcepub fn create(&self, config: NetworkConfig) -> Result<()>
pub fn create(&self, config: NetworkConfig) -> Result<()>
Create a new network. Returns error if name already exists.
Sourcepub fn remove(&self, name: &str) -> Result<NetworkConfig>
pub fn remove(&self, name: &str) -> Result<NetworkConfig>
Remove a network by name. Returns the removed config or error if not found.
Sourcepub fn list(&self) -> Result<Vec<NetworkConfig>>
pub fn list(&self) -> Result<Vec<NetworkConfig>>
List all network names.
Sourcepub fn update(&self, config: &NetworkConfig) -> Result<()>
pub fn update(&self, config: &NetworkConfig) -> Result<()>
Update a network in-place (used for connect/disconnect).
Prefer with_write_lock for a
get-modify-update sequence: update re-loads under the lock, but a
caller that read the network before calling update decided its
mutation on a possibly-stale snapshot.
Trait Implementations§
Source§impl Debug for NetworkStore
impl Debug for NetworkStore
Source§impl NetworkStoreBackend for NetworkStore
impl NetworkStoreBackend for NetworkStore
Auto Trait Implementations§
impl Freeze for NetworkStore
impl RefUnwindSafe for NetworkStore
impl Send for NetworkStore
impl Sync for NetworkStore
impl Unpin for NetworkStore
impl UnsafeUnpin for NetworkStore
impl UnwindSafe for NetworkStore
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more