Skip to main content

BufferStates

Struct BufferStates 

Source
pub struct BufferStates<S> { /* private fields */ }
Expand description

Per-buffer state for one magit mode.

One instance per state type, registered as a service at install time. Entries are published by on_activate and removed when the buffer’s mode guard drops, so a stale entry cannot outlive its buffer.

Implementations§

Source§

impl<S> BufferStates<S>

Source

pub fn publish(&self, buffer: BufferId, state: S) -> Arc<Mutex<S>> ⓘ

Publish state for buffer, replacing any prior entry (a re-activation on the same buffer supersedes the old state). Returns the shared handle so the caller can keep mutating it after an await — see the module note on late-resolved fields.

Source

pub fn publish_shared(&self, buffer: BufferId, state: Arc<Mutex<S>>)

Publish an already-shared state handle.

The peer of Self::publish for a mode that already owns an Arc<Mutex<S>> (magit-status builds one for its fold source before publishing).

Source

pub fn get(&self, buffer: BufferId) -> Option<Arc<Mutex<S>>>

The state for buffer, or None when no magit mode of this type is live on it. Handlers treat None as “not mine” and no-op — the same outcome as before, minus the race.

Source

pub fn remove(&self, buffer: BufferId)

Source

pub fn all(&self) -> Vec<Arc<Mutex<S>>>

Every live state of this type, in no particular order.

MG.21c: for handlers that must reach their mode’s buffers without being able to name one. A prompt’s -finish action fires with the PROMPT buffer’s buffer_id (see Editor::do_prompt_line_submit), so Self::get and state_for both return None there — but the work it just did still has to show up. Services are reachable from any context, so the finish handler refreshes through this instead.

Trait Implementations§

Source§

impl<S> Default for BufferStates<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S> !Freeze for BufferStates<S>

§

impl<S> RefUnwindSafe for BufferStates<S>

§

impl<S> Send for BufferStates<S>
where S: Send,

§

impl<S> Sync for BufferStates<S>
where S: Send,

§

impl<S> Unpin for BufferStates<S>

§

impl<S> UnsafeUnpin for BufferStates<S>

§

impl<S> UnwindSafe for BufferStates<S>

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more