Skip to main content

AliasStore

Struct AliasStore 

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

Persistent alias storage backed by a JSON file.

Aliases are stored at ~/.local/share/rec/aliases.json (the parent of the sessions data directory). All writes use atomic tmp-rename to prevent corruption.

Implementations§

Source§

impl AliasStore

Source

pub fn new(paths: &Paths) -> Self

Create a new AliasStore using the given paths.

The alias file is placed in the parent of data_dir (which points to ~/.local/share/rec/sessions/), giving ~/.local/share/rec/aliases.json.

Source

pub fn get(&self, alias: &str) -> Result<Option<String>>

Look up an alias by name.

Returns Ok(None) if the alias doesn’t exist or the file hasn’t been created yet.

§Errors

Returns an error if the alias file exists but cannot be read or parsed.

Source

pub fn set(&self, alias: &str, session: &str) -> Result<()>

Set an alias to point to a session name.

Overwrites any existing alias with the same name.

§Errors

Returns an error if the alias file cannot be read or written.

Source

pub fn remove(&self, alias: &str) -> Result<bool>

Remove an alias by name.

Returns Ok(true) if the alias was removed, Ok(false) if it didn’t exist.

§Errors

Returns an error if the alias file cannot be read or written.

Source

pub fn list(&self) -> Result<Vec<(String, String)>>

List all aliases sorted alphabetically by alias name.

Returns pairs of (alias_name, session_name).

§Errors

Returns an error if the alias file cannot be read or parsed.

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.