pub struct CodeView<T> { /* private fields */ }
Expand description
Save the given code and store additional information on each character
§Examples
use code_span::CodeView;
let _: CodeView<&'static str> = CodeView::from("public static class MyClass {}");
Implementations§
Source§impl<T> CodeView<T>
impl<T> CodeView<T>
Sourcepub fn blank(text: impl Into<String>) -> Selfwhere
T: Clone,
pub fn blank(text: impl Into<String>) -> Selfwhere
T: Clone,
Create a piece of code with no information
§Examples
use code_span::CodeView;
let _: CodeView<&'static str> = CodeView::blank("public static class MyClass {}");
Sourcepub fn new(text: String, info: Vec<Option<T>>) -> Self
pub fn new(text: String, info: Vec<Option<T>>) -> Self
Create a piece of code with specified information
§Examples
use code_span::CodeView;
let _: CodeView<&'static str> = CodeView::new("public".to_string(), vec![Some("keyword"); 6]);
Sourcepub fn get_text(&self) -> &str
pub fn get_text(&self) -> &str
Get original code
§Examples
use code_span::CodeView;
let view: CodeView<&'static str> = CodeView::blank("public static class MyClass {}");
assert_eq!(view.get_text(), "public static class MyClass {}");
Sourcepub fn mut_text(&mut self) -> &mut String
pub fn mut_text(&mut self) -> &mut String
Modify the original code
§Examples
use code_span::CodeView;
let mut view: CodeView<&'static str> = CodeView::blank("public static class MyClass {}");
assert_eq!(view.mut_text(), "public static class MyClass {}");
Sourcepub fn get_info(&self) -> &[Option<T>]
pub fn get_info(&self) -> &[Option<T>]
Get current information
§Examples
use code_span::CodeView;
let view: CodeView<&'static str> = CodeView::blank("public static class MyClass {}");
assert_eq!(view.get_info(), vec![None; 30]);
Sourcepub fn mut_info(&mut self) -> &mut [Option<T>]
pub fn mut_info(&mut self) -> &mut [Option<T>]
Modify current information
§Examples
use code_span::CodeView;
let mut view: CodeView<&'static str> = CodeView::blank("public");
view.mut_info().iter_mut().for_each(|v| *v = Some("keyword"));
Sourcepub fn mark_position(&mut self, start: usize, end: usize, info: Option<T>)where
T: Clone,
pub fn mark_position(&mut self, start: usize, end: usize, info: Option<T>)where
T: Clone,
Mark the information of a piece of code according to the character range
§Examples
use code_span::CodeView;
let mut view = CodeView::blank("public static class MyClass {}");
view.mark_position(0, 6, Some("keyword"));
Sourcepub fn mark_offset(&mut self, start: usize, end: usize, info: Option<T>)where
T: Clone,
pub fn mark_offset(&mut self, start: usize, end: usize, info: Option<T>)where
T: Clone,
Mark the information of a piece of code according to the byte range
§Examples
use code_span::CodeView;
let mut view = CodeView::blank("public static class MyClass {}");
view.mark_offset(0, 6, Some("keyword"));
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for CodeView<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for CodeView<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<'i, T> IntoIterator for &'i CodeView<T>
impl<'i, T> IntoIterator for &'i CodeView<T>
impl<T: Eq> Eq for CodeView<T>
impl<T> StructuralPartialEq for CodeView<T>
Auto Trait Implementations§
impl<T> Freeze for CodeView<T>
impl<T> RefUnwindSafe for CodeView<T>where
T: RefUnwindSafe,
impl<T> Send for CodeView<T>where
T: Send,
impl<T> Sync for CodeView<T>where
T: Sync,
impl<T> Unpin for CodeView<T>where
T: Unpin,
impl<T> UnwindSafe for CodeView<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more