pub struct StringLiteralFlags(/* private fields */);Expand description
Flags that can be queried to obtain information regarding the prefixes and quotes used for a string literal.
§Notes on usage
If you’re using a Generator from the ruff_python_codegen crate to generate a lint-rule fix
from an existing string literal, consider passing along the StringLiteral::flags field or
the result of the StringLiteralValue::first_literal_flags method. If you don’t have an
existing string but have a Checker from the ruff_linter crate available, consider using
Checker::default_string_flags to create instances of this struct; this method will properly
handle surrounding f-strings. For usage that doesn’t fit into one of these categories, the
public constructor StringLiteralFlags::empty can be used.
Implementations§
Source§impl StringLiteralFlags
impl StringLiteralFlags
Sourcepub fn empty() -> StringLiteralFlags
pub fn empty() -> StringLiteralFlags
Construct a new StringLiteralFlags with no flags set.
See StringLiteralFlags::with_quote_style, StringLiteralFlags::with_triple_quotes,
and StringLiteralFlags::with_prefix for ways of setting the quote style (single or
double), enabling triple quotes, and adding prefixes (such as r or u), respectively.
See the documentation for StringLiteralFlags for additional caveats on this constructor,
and situations in which alternative ways to construct this struct should be used, especially
when writing lint rules.
pub fn with_quote_style(self, quote_style: Quote) -> StringLiteralFlags
pub fn with_triple_quotes( self, triple_quotes: TripleQuotes, ) -> StringLiteralFlags
pub fn with_unclosed(self, unclosed: bool) -> StringLiteralFlags
pub fn with_prefix(self, prefix: StringLiteralPrefix) -> StringLiteralFlags
pub fn with_invalid(self) -> StringLiteralFlags
pub const fn prefix(self) -> StringLiteralPrefix
Trait Implementations§
Source§impl Clone for StringLiteralFlags
impl Clone for StringLiteralFlags
Source§fn clone(&self) -> StringLiteralFlags
fn clone(&self) -> StringLiteralFlags
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for StringLiteralFlags
impl Debug for StringLiteralFlags
Source§impl From<AnyStringFlags> for StringLiteralFlags
impl From<AnyStringFlags> for StringLiteralFlags
Source§fn from(value: AnyStringFlags) -> StringLiteralFlags
fn from(value: AnyStringFlags) -> StringLiteralFlags
Source§impl From<StringLiteralFlags> for AnyStringFlags
impl From<StringLiteralFlags> for AnyStringFlags
Source§fn from(value: StringLiteralFlags) -> AnyStringFlags
fn from(value: StringLiteralFlags) -> AnyStringFlags
Source§impl GetSize for StringLiteralFlags
impl GetSize for StringLiteralFlags
Source§fn get_heap_size(&self) -> usize
fn get_heap_size(&self) -> usize
Source§fn get_heap_size_with_tracker<TRACKER>(
&self,
tracker: TRACKER,
) -> (usize, TRACKER)where
TRACKER: GetSizeTracker,
fn get_heap_size_with_tracker<TRACKER>(
&self,
tracker: TRACKER,
) -> (usize, TRACKER)where
TRACKER: GetSizeTracker,
tracker. Read moreSource§fn get_stack_size() -> usize
fn get_stack_size() -> usize
Source§fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
fn get_size_with_tracker<T>(&self, tracker: T) -> (usize, T)where
T: GetSizeTracker,
tracker. Read moreSource§impl Hash for StringLiteralFlags
impl Hash for StringLiteralFlags
Source§impl PartialEq for StringLiteralFlags
impl PartialEq for StringLiteralFlags
Source§impl StringFlags for StringLiteralFlags
impl StringFlags for StringLiteralFlags
Source§fn quote_style(self) -> Quote
fn quote_style(self) -> Quote
Return the quoting style (single or double quotes) used by the string’s opener and closer:
"a"->QuoteStyle::Double'a'->QuoteStyle::Single
Source§fn triple_quotes(self) -> TripleQuotes
fn triple_quotes(self) -> TripleQuotes
Return true if the string is triple-quoted, i.e.,
it begins and ends with three consecutive quote characters.
For example: """bar"""
fn prefix(self) -> AnyStringPrefix
fn is_unclosed(self) -> bool
Source§fn is_triple_quoted(self) -> bool
fn is_triple_quoted(self) -> bool
Source§fn quote_str(self) -> &'static str
fn quote_str(self) -> &'static str
str representation of the quotes used to start and close.
This does not include any prefixes the string has in its opener.Source§fn quote_len(self) -> TextSize
fn quote_len(self) -> TextSize
Source§fn opener_len(self) -> TextSize
fn opener_len(self) -> TextSize
Source§fn closer_len(self) -> TextSize
fn closer_len(self) -> TextSize
self.quote_len(), except when the string is unclosed,
in which case the length is zero.fn as_any_string_flags(self) -> AnyStringFlags
fn display_contents(self, contents: &str) -> DisplayFlags<'_>
impl Copy for StringLiteralFlags
impl Eq for StringLiteralFlags
impl StructuralPartialEq for StringLiteralFlags
Auto Trait Implementations§
impl Freeze for StringLiteralFlags
impl RefUnwindSafe for StringLiteralFlags
impl Send for StringLiteralFlags
impl Sync for StringLiteralFlags
impl Unpin for StringLiteralFlags
impl UnsafeUnpin for StringLiteralFlags
impl UnwindSafe for StringLiteralFlags
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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