pub struct DocumentResource { /* private fields */ }Expand description
Host-side backing for the document WIT resource (decision A): a
point-in-time immutable snapshot. The bindgen with: mapping makes this the
resource representation, so the Store’s ResourceTable stores it directly
and [HostDocument] methods receive Resource<DocumentResource>.
Implementations§
Source§impl DocumentResource
impl DocumentResource
Sourcepub fn new(snapshot: Arc<DocumentSnapshot>) -> Self
pub fn new(snapshot: Arc<DocumentSnapshot>) -> Self
Wrap a document snapshot as a resource backing.
Sourcepub fn get_text_range(&self, range: NativeRange) -> Result<String, String>
pub fn get_text_range(&self, range: NativeRange) -> Result<String, String>
The text of the [start, end) byte range. Slices only the requested
range out of the rope; the whole document is never materialised. Err
on an out-of-range or end < start range (mirrors Buffer::slice).
Sourcepub fn line_count(&self) -> u32
pub fn line_count(&self) -> u32
Lines the document has, in the sense the WIT contract means:
"a\nb\n" is two lines.
CV.3: content space. This surfaced ropey’s raw count, so a
guest iterating 0..line-count and calling line(n) got one
phantom empty line at the end of every normal file — a
rope-implementation detail leaking across the plugin boundary,
which every guest author would then have to rediscover and
correct for.
Sourcepub fn line_at(&self, n: u32) -> Option<String>
pub fn line_at(&self, n: u32) -> Option<String>
Line n (0-based) without its trailing newline (matching
Buffer::line), or None past EOF.
Sourcepub fn path(&self) -> Option<String>
pub fn path(&self) -> Option<String>
OM.6b: the file backing this document, absolute; None for a buffer
with no path on disk.
A non-UTF-8 path also answers None rather than erroring. The WIT
signature has no error channel on purpose — the guest’s question is
“can I name a file next to mine”, and “no” is a complete answer to it.
Erroring would make one oddly-named file fail an action that has
nothing to do with encoding.
Auto Trait Implementations§
impl Freeze for DocumentResource
impl RefUnwindSafe for DocumentResource
impl Send for DocumentResource
impl Sync for DocumentResource
impl Unpin for DocumentResource
impl UnsafeUnpin for DocumentResource
impl UnwindSafe for DocumentResource
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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