pub struct Talks { /* private fields */ }Expand description
A conversation store on disk.
Implementations§
Source§impl Talks
impl Talks
Sourcepub fn at(root: PathBuf) -> Self
pub fn at(root: PathBuf) -> Self
A store at an explicit root. Tests use this, which is why none of them need the operator’s real home.
Sourcepub fn artifacts_of(&self, id: &str) -> PathBuf
pub fn artifacts_of(&self, id: &str) -> PathBuf
Where one conversation’s prompts and CLI output are kept, beside the record rather than inside it.
Sourcepub fn attachments_dir(&self, id: &str) -> PathBuf
pub fn attachments_dir(&self, id: &str) -> PathBuf
Where this conversation’s attached images live: a subdirectory of
artifacts_of, so deleting the conversation deletes its attachments
too and nothing here needs its own cleanup path.
Sourcepub fn put_attachment(
&self,
id: &str,
mime: &str,
name: &str,
data: &[u8],
) -> Result<Attachment>
pub fn put_attachment( &self, id: &str, mime: &str, name: &str, data: &[u8], ) -> Result<Attachment>
Persist one already-validated attachment and return its metadata.
web::talk_attachment_post is the only caller: it has already
checked mime against the whitelist and sniffed the bytes, so an
unrecognised mime reaching here is a bug in that caller, not
something an operator did. The id is minted here and never taken
from the client; name is stored for display only and never used to
build a path.
Sourcepub fn attachment_meta(
&self,
id: &str,
att_id: &str,
) -> Result<Option<Attachment>>
pub fn attachment_meta( &self, id: &str, att_id: &str, ) -> Result<Option<Attachment>>
Just the metadata, without reading the image bytes back off disk -
what web::talk_say uses to turn an id the operator referenced into
an Attachment before appending a Turn, where the bytes
themselves are of no interest. None for an id this conversation
never stored - including one that merely looks plausible:
valid_attachment_id is checked here too, not only by the caller,
the same defence-in-depth Questions::panel_asset uses for its own
asset ids.
Sourcepub fn read_attachment(
&self,
id: &str,
att_id: &str,
) -> Result<Option<(Attachment, Vec<u8>)>>
pub fn read_attachment( &self, id: &str, att_id: &str, ) -> Result<Option<(Attachment, Vec<u8>)>>
A stored attachment’s metadata and its bytes together, for serving it
back on GET. None under the same conditions as
Talks::attachment_meta, which this is built on.
Sourcepub fn put(&self, t: &mut Talk) -> Result<()>
pub fn put(&self, t: &mut Talk) -> Result<()>
Write a conversation, atomically, so a process killed mid-write leaves the previous state readable rather than a truncated file.
Sourcepub fn get(&self, id: &str) -> Result<Talk>
pub fn get(&self, id: &str) -> Result<Talk>
Load a conversation by id or unambiguous id prefix.
Sourcepub fn list(&self) -> Vec<Talk>
pub fn list(&self) -> Vec<Talk>
Every conversation on disk: open first, then newest first, so what the operator is still using belongs above what they are done with.
Sourcepub fn resolve_id(&self, prefix: &str) -> Result<String>
pub fn resolve_id(&self, prefix: &str) -> Result<String>
Expand an id prefix to exactly one conversation id.
Sourcepub fn revision(&self) -> u64
pub fn revision(&self) -> u64
Change detection token: the newest modification time in the store, in milliseconds.
Sourcepub fn count_open(&self) -> usize
pub fn count_open(&self) -> usize
How many conversations are still open.
Sourcepub fn remove(&self, id: &str) -> Result<()>
pub fn remove(&self, id: &str) -> Result<()>
Remove a conversation from disk, record and artifacts both. The
operator’s way of saying “not just done, gone” - close alone
leaves the record as history.
Takes Talks::guard for the same reason close does: a delete
racing a record or the tail of [turn] must not land between
their own read and write, or the file removed here would look, to
them, like a record that simply has not been written yet. The other
half of that story is on their side - both check under this same
guard that the record they are about to write is still there, and
give up without writing if it is not, which is what stops their put
from resurrecting a conversation this call already removed.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Talks
impl RefUnwindSafe for Talks
impl Send for Talks
impl Sync for Talks
impl Unpin for Talks
impl UnsafeUnpin for Talks
impl UnwindSafe for Talks
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<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