pub struct TStringFlags(/* private fields */);Expand description
Flags that can be queried to obtain information regarding the prefixes and quotes used for an f-string.
Note: This is identical to FStringFlags except that
the implementation of the prefix method of the
StringFlags trait returns a variant of
AnyStringPrefix::Template.
§Notes on usage
If you’re using a Generator from the ruff_python_codegen crate to generate a lint-rule fix
from an existing t-string literal, consider passing along the FString::flags field. If you
don’t have an existing literal but have a Checker from the ruff_linter crate available,
consider using Checker::default_tstring_flags to create instances of this struct; this method
will properly handle nested t-strings. For usage that doesn’t fit into one of these categories,
the public constructor TStringFlags::empty can be used.
Implementations§
Source§impl TStringFlags
impl TStringFlags
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Construct a new TStringFlags with no flags set.
See TStringFlags::with_quote_style, TStringFlags::with_triple_quotes, and
TStringFlags::with_prefix for ways of setting the quote style (single or double),
enabling triple quotes, and adding prefixes (such as r), respectively.
See the documentation for TStringFlags 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) -> Self
pub fn with_triple_quotes(self, triple_quotes: TripleQuotes) -> Self
pub fn with_unclosed(self, unclosed: bool) -> Self
pub fn with_prefix(self, prefix: TStringPrefix) -> Self
pub const fn prefix(self) -> TStringPrefix
Trait Implementations§
Source§impl Clone for TStringFlags
impl Clone for TStringFlags
Source§fn clone(&self) -> TStringFlags
fn clone(&self) -> TStringFlags
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TStringFlags
impl Debug for TStringFlags
Source§impl From<AnyStringFlags> for TStringFlags
impl From<AnyStringFlags> for TStringFlags
Source§fn from(value: AnyStringFlags) -> TStringFlags
fn from(value: AnyStringFlags) -> TStringFlags
Source§impl From<TStringFlags> for AnyStringFlags
impl From<TStringFlags> for AnyStringFlags
Source§fn from(value: TStringFlags) -> Self
fn from(value: TStringFlags) -> Self
Source§impl Hash for TStringFlags
impl Hash for TStringFlags
Source§impl PartialEq for TStringFlags
impl PartialEq for TStringFlags
Source§impl StringFlags for TStringFlags
impl StringFlags for TStringFlags
Source§fn triple_quotes(self) -> TripleQuotes
fn triple_quotes(self) -> TripleQuotes
Return true if the t-string is triple-quoted, i.e.,
it begins and ends with three consecutive quote characters.
For example: t"""{bar}"""
Source§fn quote_style(self) -> Quote
fn quote_style(self) -> Quote
Return the quoting style (single or double quotes) used by the t-string’s opener and closer:
t"{"a"}"->QuoteStyle::Doublet'{"a"}'->QuoteStyle::Single
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 TStringFlags
impl Eq for TStringFlags
impl StructuralPartialEq for TStringFlags
Auto Trait Implementations§
impl Freeze for TStringFlags
impl RefUnwindSafe for TStringFlags
impl Send for TStringFlags
impl Sync for TStringFlags
impl Unpin for TStringFlags
impl UnsafeUnpin for TStringFlags
impl UnwindSafe for TStringFlags
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<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