pub struct BytesLiteralFlags(/* private fields */);Expand description
Flags that can be queried to obtain information regarding the prefixes and quotes used for a bytes 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 bytes literal, consider passing along the BytesLiteral::flags field. If
you don’t have an existing literal but have a Checker from the ruff_linter crate available,
consider using Checker::default_bytes_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 BytesLiteralFlags::empty can be used.
Implementations§
Source§impl BytesLiteralFlags
impl BytesLiteralFlags
Sourcepub fn empty() -> BytesLiteralFlags
pub fn empty() -> BytesLiteralFlags
Construct a new BytesLiteralFlags with no flags set.
See BytesLiteralFlags::with_quote_style, BytesLiteralFlags::with_triple_quotes, and
BytesLiteralFlags::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 BytesLiteralFlags 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) -> BytesLiteralFlags
pub fn with_triple_quotes( self, triple_quotes: TripleQuotes, ) -> BytesLiteralFlags
pub fn with_unclosed(self, unclosed: bool) -> BytesLiteralFlags
pub fn with_prefix(self, prefix: ByteStringPrefix) -> BytesLiteralFlags
pub fn with_invalid(self) -> BytesLiteralFlags
pub const fn prefix(self) -> ByteStringPrefix
Trait Implementations§
Source§impl Clone for BytesLiteralFlags
impl Clone for BytesLiteralFlags
Source§fn clone(&self) -> BytesLiteralFlags
fn clone(&self) -> BytesLiteralFlags
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for BytesLiteralFlags
impl Debug for BytesLiteralFlags
Source§impl From<AnyStringFlags> for BytesLiteralFlags
impl From<AnyStringFlags> for BytesLiteralFlags
Source§fn from(value: AnyStringFlags) -> BytesLiteralFlags
fn from(value: AnyStringFlags) -> BytesLiteralFlags
Source§impl From<BytesLiteralFlags> for AnyStringFlags
impl From<BytesLiteralFlags> for AnyStringFlags
Source§fn from(value: BytesLiteralFlags) -> AnyStringFlags
fn from(value: BytesLiteralFlags) -> AnyStringFlags
Source§impl GetSize for BytesLiteralFlags
impl GetSize for BytesLiteralFlags
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 BytesLiteralFlags
impl Hash for BytesLiteralFlags
Source§impl PartialEq for BytesLiteralFlags
impl PartialEq for BytesLiteralFlags
Source§impl StringFlags for BytesLiteralFlags
impl StringFlags for BytesLiteralFlags
Source§fn triple_quotes(self) -> TripleQuotes
fn triple_quotes(self) -> TripleQuotes
Return true if the bytestring is triple-quoted, i.e.,
it begins and ends with three consecutive quote characters.
For example: b"""{bar}"""
Source§fn quote_style(self) -> Quote
fn quote_style(self) -> Quote
Return the quoting style (single or double quotes) used by the bytestring’s opener and closer:
b"a"->QuoteStyle::Doubleb'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 BytesLiteralFlags
impl Eq for BytesLiteralFlags
impl StructuralPartialEq for BytesLiteralFlags
Auto Trait Implementations§
impl Freeze for BytesLiteralFlags
impl RefUnwindSafe for BytesLiteralFlags
impl Send for BytesLiteralFlags
impl Sync for BytesLiteralFlags
impl Unpin for BytesLiteralFlags
impl UnsafeUnpin for BytesLiteralFlags
impl UnwindSafe for BytesLiteralFlags
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