mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-17 09:00:26 +00:00
[internal] ComparableExpr
(f)strings and bytes made invariant under concatenation (#13301)
This commit is contained in:
parent
ca0ae0a484
commit
f27a8b8c7a
3 changed files with 173 additions and 38 deletions
|
@ -1,5 +1,6 @@
|
|||
#![allow(clippy::derive_partial_eq_without_eq)]
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
use std::fmt::Debug;
|
||||
use std::iter::FusedIterator;
|
||||
|
@ -2186,6 +2187,22 @@ impl PartialEq<[u8]> for BytesLiteralValue {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a BytesLiteralValue> for Cow<'a, [u8]> {
|
||||
fn from(value: &'a BytesLiteralValue) -> Self {
|
||||
match &value.inner {
|
||||
BytesLiteralValueInner::Single(BytesLiteral {
|
||||
value: bytes_value, ..
|
||||
}) => Cow::from(bytes_value.as_ref()),
|
||||
BytesLiteralValueInner::Concatenated(bytes_literal_vec) => Cow::Owned(
|
||||
bytes_literal_vec
|
||||
.iter()
|
||||
.flat_map(|bytes_literal| bytes_literal.value.to_vec())
|
||||
.collect::<Vec<u8>>(),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An internal representation of [`BytesLiteralValue`].
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
enum BytesLiteralValueInner {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue