Struct Document

Source
pub struct Document {
    pub id: DocumentId,
    pub path: Option<PathBuf>,
    pub source: DocumentSource,
    pub language: EditorLanguage,
    pub version: DocumentVersion,
    pub dirty: bool,
    pub buffer: TextBuffer,
}
Expand description

Open document metadata plus rope-backed text.

Fields are public for controlled editor composition. Changing buffer directly does not increment version or set dirty; session methods should mediate edits when those invariants matter.

§Examples

use ailloli_ui_editor::{Document, DocumentId, DocumentVersion, EditorLanguage};
use ailloli_ui_text::TextBuffer;
let document = Document::new(DocumentId(1), TextBuffer::from_string("hello"));
assert_eq!(document.version, DocumentVersion(0));
assert_eq!(document.language, EditorLanguage::PlainText);
assert!(!document.dirty);

Fields§

§id: DocumentId

Stable session-local document identity.

§path: Option<PathBuf>

Optional local path retained for compatibility and language detection.

§source: DocumentSource

Canonical memory/path/URI origin description.

§language: EditorLanguage

Explicit or detected language.

§version: DocumentVersion

Content revision; initialized to zero.

§dirty: bool

Whether content differs from its externally saved version.

§buffer: TextBuffer

Rope-backed UTF-8 content.

Implementations§

Source§

impl Document

Document construction and language-hint operations.

Source

pub fn new(id: DocumentId, buffer: TextBuffer) -> Self

Creates a clean, version-zero in-memory plain-text document.

§Examples
use ailloli_ui_editor::{Document, DocumentId, DocumentSource};
use ailloli_ui_text::TextBuffer;
let document = Document::new(DocumentId(2), TextBuffer::new());
assert_eq!(document.source, DocumentSource::Memory);
assert!(document.path.is_none());
Source

pub fn with_path(self, path: impl Into<PathBuf>) -> Self

Sets both path and DocumentSource::LocalPath without detection.

§Examples
use ailloli_ui_editor::{Document, DocumentId, DocumentSource};
use ailloli_ui_text::TextBuffer;
let document = Document::new(DocumentId(1), TextBuffer::new()).with_path("src/main.rs");
assert!(matches!(document.source, DocumentSource::LocalPath(_)));
assert_eq!(document.path.unwrap().to_str(), Some("src/main.rs"));
Source

pub fn with_source(self, source: DocumentSource) -> Self

Replaces the origin and synchronizes the optional local path.

Memory preserves an existing legacy path, a local file URI converts to a host path when possible, and non-file URIs clear path.

§Examples
use ailloli_ui_editor::{Document, DocumentId, DocumentSource};
use ailloli_ui_fs::FileUri;
use ailloli_ui_text::TextBuffer;
let document = Document::new(DocumentId(1), TextBuffer::new())
    .with_source(DocumentSource::Uri(FileUri::parse("sftp://host/main.rs")?));
assert!(document.path.is_none());
Source

pub fn with_uri(self, uri: FileUri) -> Self

Convenience wrapper for Self::with_source with a URI origin.

§Examples
use ailloli_ui_editor::{Document, DocumentId, DocumentSource};
use ailloli_ui_fs::FileUri;
use ailloli_ui_text::TextBuffer;
let document = Document::new(DocumentId(1), TextBuffer::new()).with_uri(FileUri::parse("sftp://host/doc")?);
assert!(matches!(document.source, DocumentSource::Uri(_)));
Source

pub fn with_language(self, language: EditorLanguage) -> Self

Replaces the language without inspecting the path or buffer.

§Examples
use ailloli_ui_editor::{Document, DocumentId, EditorLanguage};
use ailloli_ui_text::TextBuffer;
let document = Document::new(DocumentId(1), TextBuffer::new()).with_language(EditorLanguage::Rust);
assert_eq!(document.language, EditorLanguage::Rust);
Source

pub fn detect_language(&mut self)

Replaces the current language with extension-based detection.

With no hint this selects PlainText; an unrecognized extension selects Unknown, even if a different explicit language was previously set.

§Examples
use ailloli_ui_editor::{Document, DocumentId, EditorLanguage};
use ailloli_ui_text::TextBuffer;
let mut document = Document::new(DocumentId(1), TextBuffer::new()).with_path("lib.rs");
document.detect_language();
assert_eq!(document.language, EditorLanguage::Rust);
Source

pub fn language_path_hint(&self) -> Option<&Path>

Returns path first, then the source-derived hint.

§Examples
use std::path::Path;
use ailloli_ui_editor::{Document, DocumentId};
use ailloli_ui_text::TextBuffer;
let document = Document::new(DocumentId(1), TextBuffer::new()).with_path("main.rs");
assert_eq!(document.language_path_hint(), Some(Path::new("main.rs")));

Trait Implementations§

Source§

impl Clone for Document

Source§

fn clone(&self) -> Document

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Document

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> ErasedDestructor for T
where T: 'static,