pub struct FStringFlags(/* 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 TStringFlags except that
the implementation of the prefix method of the
StringFlags trait returns a variant of
AnyStringPrefix::Format.
§Notes on usage
If you’re using a Generator from the ruff_python_codegen crate to generate a lint-rule fix
from an existing f-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_fstring_flags to create instances of this struct; this method
will properly handle nested f-strings. For usage that doesn’t fit into one of these categories,
the public constructor FStringFlags::empty can be used.
Implementations§
Source§impl FStringFlags
impl FStringFlags
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Construct a new FStringFlags with no flags set.
See FStringFlags::with_quote_style, FStringFlags::with_triple_quotes, and
FStringFlags::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 FStringFlags 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: FStringPrefix) -> Self
pub const fn prefix(self) -> FStringPrefix
Trait Implementations§
Source§impl Clone for FStringFlags
impl Clone for FStringFlags
Source§fn clone(&self) -> FStringFlags
fn clone(&self) -> FStringFlags
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FStringFlags
impl Debug for FStringFlags
Source§impl From<AnyStringFlags> for FStringFlags
impl From<AnyStringFlags> for FStringFlags
Source§fn from(value: AnyStringFlags) -> FStringFlags
fn from(value: AnyStringFlags) -> FStringFlags
Source§impl From<FStringFlags> for AnyStringFlags
impl From<FStringFlags> for AnyStringFlags
Source§fn from(value: FStringFlags) -> Self
fn from(value: FStringFlags) -> Self
Source§impl Hash for FStringFlags
impl Hash for FStringFlags
Source§impl PartialEq for FStringFlags
impl PartialEq for FStringFlags
Source§impl StringFlags for FStringFlags
impl StringFlags for FStringFlags
Source§fn triple_quotes(self) -> TripleQuotes
fn triple_quotes(self) -> TripleQuotes
Return true if the f-string is triple-quoted, i.e.,
it begins and ends with three consecutive quote characters.
For example: f"""{bar}"""
Source§fn quote_style(self) -> Quote
fn quote_style(self) -> Quote
Return the quoting style (single or double quotes) used by the f-string’s opener and closer:
f"{"a"}"->QuoteStyle::Doublef'{"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 FStringFlags
impl Eq for FStringFlags
impl StructuralPartialEq for FStringFlags
Auto Trait Implementations§
impl Freeze for FStringFlags
impl RefUnwindSafe for FStringFlags
impl Send for FStringFlags
impl Sync for FStringFlags
impl Unpin for FStringFlags
impl UnsafeUnpin for FStringFlags
impl UnwindSafe for FStringFlags
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