#[non_exhaustive]pub struct ImePreedit {
pub text: String,
pub selection: Option<(usize, usize)>,
}Expand description
In-progress IME composition (preedit) text and selection.
§Examples
use ailloli_ui_core::event::ImePreedit;
let preedit = ImePreedit::try_new("é", Some((0, 2)))?;
assert_eq!(preedit.selection(), Some((0, 2)));Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.text: StringCurrent uncommitted UTF-8 composition text; an empty string is valid.
selection: Option<(usize, usize)>Caret/selection range inside text as UTF-8 byte indices.
None means the provider did not expose a range. Equal indices denote
a caret; distinct indices denote the selected preedit span.
Implementations§
Source§impl ImePreedit
impl ImePreedit
Sourcepub fn new(text: impl Into<String>) -> Self
pub fn new(text: impl Into<String>) -> Self
Creates preedit text without an explicit selection.
§Examples
use ailloli_ui_core::event::ImePreedit;
assert_eq!(ImePreedit::new("かな").selection(), None);Sourcepub fn try_new(
text: impl Into<String>,
selection: Option<(usize, usize)>,
) -> Result<Self, ImePreeditError>
pub fn try_new( text: impl Into<String>, selection: Option<(usize, usize)>, ) -> Result<Self, ImePreeditError>
Creates preedit text after validating UTF-8 byte selection indices.
§Errors
Returns ImePreeditError when a supplied range is reversed, exceeds
the text length, or is not aligned to UTF-8 character boundaries.
§Examples
use ailloli_ui_core::event::ImePreedit;
let preedit = ImePreedit::try_new("かな", Some((0, 3)))?;
assert_eq!(preedit.text(), "かな");Sourcepub fn text(&self) -> &str
pub fn text(&self) -> &str
Current preedit text.
§Examples
use ailloli_ui_core::event::ImePreedit;
assert_eq!(ImePreedit::new("かな").text(), "かな");Sourcepub const fn selection(&self) -> Option<(usize, usize)>
pub const fn selection(&self) -> Option<(usize, usize)>
Caret/selection range as validated UTF-8 byte indices.
§Examples
use ailloli_ui_core::event::ImePreedit;
assert_eq!(ImePreedit::try_new("abc", Some((1, 1)))?.selection(), Some((1, 1)));Sourcepub fn into_text(self) -> String
pub fn into_text(self) -> String
Consumes the payload and returns its text.
§Examples
use ailloli_ui_core::event::ImePreedit;
assert_eq!(ImePreedit::new("かな").into_text(), "かな");Sourcepub fn validate(&self) -> Result<(), ImePreeditError>
pub fn validate(&self) -> Result<(), ImePreeditError>
Validates selection ordering, bounds, and UTF-8 character boundaries.
§Errors
Returns the first violated range invariant without including composition text in the error, so potentially sensitive input is not echoed.
§Examples
use ailloli_ui_core::event::ImePreedit;
assert!(ImePreedit::try_new("abc", Some((0, 3)))?.validate().is_ok());Trait Implementations§
Source§impl Clone for ImePreedit
impl Clone for ImePreedit
Source§fn clone(&self) -> ImePreedit
fn clone(&self) -> ImePreedit
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more