Skip to content

Commit f4cfca9

Browse files
committed
Rename CompactCowStr to CowRcStr
1 parent 3b1906b commit f4cfca9

File tree

7 files changed

+58
-58
lines changed

7 files changed

+58
-58
lines changed

src/compact_cow_str.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::usize;
2020
///
2121
/// FIXME(https://github.com/rust-lang/rfcs/issues/1230): use an actual enum if/when
2222
/// the compiler can do this layout optimization.
23-
pub struct CompactCowStr<'a> {
23+
pub struct CowRcStr<'a> {
2424
/// FIXME: https://github.com/rust-lang/rust/issues/27730 use NonZero or Shared
2525
/// In the meantime we abuse `&'static _` to get the effect of `NonZero<*const _>`.
2626
/// `ptr` doesn’t really have the 'static lifetime!
@@ -39,35 +39,35 @@ pub struct CompactCowStr<'a> {
3939

4040
fn _static_assert_same_size<'a>() {
4141
// "Instantiate" the generic function without calling it.
42-
let _ = mem::transmute::<CompactCowStr<'a>, Option<CompactCowStr<'a>>>;
42+
let _ = mem::transmute::<CowRcStr<'a>, Option<CowRcStr<'a>>>;
4343
}
4444

45-
impl<'a> From<&'a str> for CompactCowStr<'a> {
45+
impl<'a> From<&'a str> for CowRcStr<'a> {
4646
#[inline]
4747
fn from(s: &'a str) -> Self {
4848
let len = s.len();
4949
assert!(len < usize::MAX);
50-
CompactCowStr {
50+
CowRcStr {
5151
ptr: unsafe { &*(s.as_ptr() as *const ()) },
5252
borrowed_len_or_max: len,
5353
phantom: PhantomData,
5454
}
5555
}
5656
}
5757

58-
impl<'a> From<Rc<String>> for CompactCowStr<'a> {
58+
impl<'a> From<Rc<String>> for CowRcStr<'a> {
5959
#[inline]
6060
fn from(s: Rc<String>) -> Self {
6161
let ptr = unsafe { &*(Rc::into_raw(s) as *const ()) };
62-
CompactCowStr {
62+
CowRcStr {
6363
ptr: ptr,
6464
borrowed_len_or_max: usize::MAX,
6565
phantom: PhantomData,
6666
}
6767
}
6868
}
6969

70-
impl<'a> CompactCowStr<'a> {
70+
impl<'a> CowRcStr<'a> {
7171
#[inline]
7272
fn unpack(&self) -> Result<&'a str, *const String> {
7373
if self.borrowed_len_or_max == usize::MAX {
@@ -105,7 +105,7 @@ impl<'a> CompactCowStr<'a> {
105105
}
106106
}
107107

108-
impl<'a> Clone for CompactCowStr<'a> {
108+
impl<'a> Clone for CowRcStr<'a> {
109109
#[inline]
110110
fn clone(&self) -> Self {
111111
match self.unpack() {
@@ -118,13 +118,13 @@ impl<'a> Clone for CompactCowStr<'a> {
118118
new_rc.into()
119119
}
120120
Ok(_) => {
121-
CompactCowStr { ..*self }
121+
CowRcStr { ..*self }
122122
}
123123
}
124124
}
125125
}
126126

127-
impl<'a> Drop for CompactCowStr<'a> {
127+
impl<'a> Drop for CowRcStr<'a> {
128128
#[inline]
129129
fn drop(&mut self) {
130130
if let Err(ptr) = self.unpack() {
@@ -135,7 +135,7 @@ impl<'a> Drop for CompactCowStr<'a> {
135135
}
136136
}
137137

138-
impl<'a> Deref for CompactCowStr<'a> {
138+
impl<'a> Deref for CowRcStr<'a> {
139139
type Target = str;
140140

141141
#[inline]
@@ -146,9 +146,9 @@ impl<'a> Deref for CompactCowStr<'a> {
146146
}
147147
}
148148

149-
impl<'a> From<CompactCowStr<'a>> for Cow<'a, str> {
149+
impl<'a> From<CowRcStr<'a>> for Cow<'a, str> {
150150
#[inline]
151-
fn from(cow: CompactCowStr<'a>) -> Self {
151+
fn from(cow: CowRcStr<'a>) -> Self {
152152
match cow.into_enum() {
153153
Ok(s) => Cow::Borrowed(s),
154154
Err(rc) => match Rc::try_unwrap(rc) {
@@ -159,14 +159,14 @@ impl<'a> From<CompactCowStr<'a>> for Cow<'a, str> {
159159
}
160160
}
161161

162-
impl<'a> From<String> for CompactCowStr<'a> {
162+
impl<'a> From<String> for CowRcStr<'a> {
163163
#[inline]
164164
fn from(s: String) -> Self {
165165
Self::from(Rc::new(s))
166166
}
167167
}
168168

169-
impl<'a> From<Cow<'a, str>> for CompactCowStr<'a> {
169+
impl<'a> From<Cow<'a, str>> for CowRcStr<'a> {
170170
#[inline]
171171
fn from(s: Cow<'a, str>) -> Self {
172172
match s {
@@ -179,65 +179,65 @@ impl<'a> From<Cow<'a, str>> for CompactCowStr<'a> {
179179

180180
// Boilerplate / trivial impls below.
181181

182-
impl<'a> AsRef<str> for CompactCowStr<'a> {
182+
impl<'a> AsRef<str> for CowRcStr<'a> {
183183
#[inline]
184184
fn as_ref(&self) -> &str {
185185
self
186186
}
187187
}
188188

189-
impl<'a> Borrow<str> for CompactCowStr<'a> {
189+
impl<'a> Borrow<str> for CowRcStr<'a> {
190190
#[inline]
191191
fn borrow(&self) -> &str {
192192
self
193193
}
194194
}
195195

196-
impl<'a> Default for CompactCowStr<'a> {
196+
impl<'a> Default for CowRcStr<'a> {
197197
#[inline]
198198
fn default() -> Self {
199199
Self::from("")
200200
}
201201
}
202202

203-
impl<'a> hash::Hash for CompactCowStr<'a> {
203+
impl<'a> hash::Hash for CowRcStr<'a> {
204204
#[inline]
205205
fn hash<H: hash::Hasher>(&self, hasher: &mut H) {
206206
str::hash(self, hasher)
207207
}
208208
}
209209

210-
impl<'a, T: AsRef<str>> PartialEq<T> for CompactCowStr<'a> {
210+
impl<'a, T: AsRef<str>> PartialEq<T> for CowRcStr<'a> {
211211
#[inline]
212212
fn eq(&self, other: &T) -> bool {
213213
str::eq(self, other.as_ref())
214214
}
215215
}
216216

217-
impl<'a, T: AsRef<str>> PartialOrd<T> for CompactCowStr<'a> {
217+
impl<'a, T: AsRef<str>> PartialOrd<T> for CowRcStr<'a> {
218218
#[inline]
219219
fn partial_cmp(&self, other: &T) -> Option<cmp::Ordering> {
220220
str::partial_cmp(self, other.as_ref())
221221
}
222222
}
223223

224-
impl<'a> Eq for CompactCowStr<'a> {}
224+
impl<'a> Eq for CowRcStr<'a> {}
225225

226-
impl<'a> Ord for CompactCowStr<'a> {
226+
impl<'a> Ord for CowRcStr<'a> {
227227
#[inline]
228228
fn cmp(&self, other: &Self) -> cmp::Ordering {
229229
str::cmp(self, other)
230230
}
231231
}
232232

233-
impl<'a> fmt::Display for CompactCowStr<'a> {
233+
impl<'a> fmt::Display for CowRcStr<'a> {
234234
#[inline]
235235
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
236236
str::fmt(self, formatter)
237237
}
238238
}
239239

240-
impl<'a> fmt::Debug for CompactCowStr<'a> {
240+
impl<'a> fmt::Debug for CowRcStr<'a> {
241241
#[inline]
242242
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
243243
str::fmt(self, formatter)

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub use nth::parse_nth;
9191
pub use serializer::{ToCss, CssStringWriter, serialize_identifier, serialize_string, TokenSerializationType};
9292
pub use parser::{Parser, Delimiter, Delimiters, SourcePosition, ParseError, BasicParseError, ParserInput};
9393
pub use unicode_range::UnicodeRange;
94-
pub use compact_cow_str::CompactCowStr;
94+
pub use compact_cow_str::CowRcStr;
9595

9696
// For macros
9797
#[doc(hidden)] pub use macros::_internal__to_lowercase;

src/parser.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use compact_cow_str::CompactCowStr;
5+
use compact_cow_str::CowRcStr;
66
use std::ops::Range;
77
use std::ascii::AsciiExt;
88
use std::ops::BitOr;
@@ -28,7 +28,7 @@ pub enum BasicParseError<'a> {
2828
/// The end of the input was encountered unexpectedly.
2929
EndOfInput,
3030
/// An `@` rule was encountered that was invalid.
31-
AtRuleInvalid(CompactCowStr<'a>),
31+
AtRuleInvalid(CowRcStr<'a>),
3232
/// The body of an '@' rule was invalid.
3333
AtRuleBodyInvalid,
3434
/// A qualified rule was encountered that was invalid.
@@ -446,7 +446,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
446446

447447
/// Parse a <ident-token> and return the unescaped value.
448448
#[inline]
449-
pub fn expect_ident(&mut self) -> Result<CompactCowStr<'i>, BasicParseError<'i>> {
449+
pub fn expect_ident(&mut self) -> Result<CowRcStr<'i>, BasicParseError<'i>> {
450450
match self.next()? {
451451
Token::Ident(value) => Ok(value),
452452
t => Err(BasicParseError::UnexpectedToken(t))
@@ -464,7 +464,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
464464

465465
/// Parse a <string-token> and return the unescaped value.
466466
#[inline]
467-
pub fn expect_string(&mut self) -> Result<CompactCowStr<'i>, BasicParseError<'i>> {
467+
pub fn expect_string(&mut self) -> Result<CowRcStr<'i>, BasicParseError<'i>> {
468468
match self.next()? {
469469
Token::QuotedString(value) => Ok(value),
470470
t => Err(BasicParseError::UnexpectedToken(t))
@@ -473,7 +473,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
473473

474474
/// Parse either a <ident-token> or a <string-token>, and return the unescaped value.
475475
#[inline]
476-
pub fn expect_ident_or_string(&mut self) -> Result<CompactCowStr<'i>, BasicParseError<'i>> {
476+
pub fn expect_ident_or_string(&mut self) -> Result<CowRcStr<'i>, BasicParseError<'i>> {
477477
match self.next()? {
478478
Token::Ident(value) => Ok(value),
479479
Token::QuotedString(value) => Ok(value),
@@ -483,7 +483,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
483483

484484
/// Parse a <url-token> and return the unescaped value.
485485
#[inline]
486-
pub fn expect_url(&mut self) -> Result<CompactCowStr<'i>, BasicParseError<'i>> {
486+
pub fn expect_url(&mut self) -> Result<CowRcStr<'i>, BasicParseError<'i>> {
487487
match self.next()? {
488488
Token::UnquotedUrl(value) => Ok(value),
489489
Token::Function(ref name) if name.eq_ignore_ascii_case("url") => {
@@ -496,7 +496,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
496496

497497
/// Parse either a <url-token> or a <string-token>, and return the unescaped value.
498498
#[inline]
499-
pub fn expect_url_or_string(&mut self) -> Result<CompactCowStr<'i>, BasicParseError<'i>> {
499+
pub fn expect_url_or_string(&mut self) -> Result<CowRcStr<'i>, BasicParseError<'i>> {
500500
match self.next()? {
501501
Token::UnquotedUrl(value) => Ok(value),
502502
Token::QuotedString(value) => Ok(value),
@@ -612,7 +612,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
612612
///
613613
/// If the result is `Ok`, you can then call the `Parser::parse_nested_block` method.
614614
#[inline]
615-
pub fn expect_function(&mut self) -> Result<CompactCowStr<'i>, BasicParseError<'i>> {
615+
pub fn expect_function(&mut self) -> Result<CowRcStr<'i>, BasicParseError<'i>> {
616616
match self.next()? {
617617
Token::Function(name) => Ok(name),
618618
t => Err(BasicParseError::UnexpectedToken(t))

src/rules_and_declarations.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
// https://drafts.csswg.org/css-syntax/#parsing
66

7-
use compact_cow_str::CompactCowStr;
7+
use compact_cow_str::CowRcStr;
88
use parser::{parse_until_before, parse_until_after, parse_nested_block};
99
use std::ascii::AsciiExt;
1010
use std::ops::Range;
@@ -72,7 +72,7 @@ pub trait DeclarationParser<'i> {
7272
/// If `!important` can be used in a given context,
7373
/// `input.try(parse_important).is_ok()` should be used at the end
7474
/// of the implementation of this method and the result should be part of the return value.
75-
fn parse_value<'t>(&mut self, name: CompactCowStr<'i>, input: &mut Parser<'i, 't>)
75+
fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
7676
-> Result<Self::Declaration, ParseError<'i, Self::Error>>;
7777
}
7878

@@ -112,7 +112,7 @@ pub trait AtRuleParser<'i> {
112112
/// The given `input` is a "delimited" parser
113113
/// that ends wherever the prelude should end.
114114
/// (Before the next semicolon, the next `{`, or the end of the current block.)
115-
fn parse_prelude<'t>(&mut self, name: CompactCowStr<'i>, input: &mut Parser<'i, 't>)
115+
fn parse_prelude<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
116116
-> Result<AtRuleType<Self::Prelude, Self::AtRule>, ParseError<'i, Self::Error>> {
117117
let _ = name;
118118
let _ = input;
@@ -407,7 +407,7 @@ pub struct PreciseParseError<'i, E: 'i> {
407407
pub span: Range<SourcePosition>,
408408
}
409409

410-
fn parse_at_rule<'i: 't, 't, P, E>(start_position: SourcePosition, name: CompactCowStr<'i>,
410+
fn parse_at_rule<'i: 't, 't, P, E>(start_position: SourcePosition, name: CowRcStr<'i>,
411411
input: &mut Parser<'i, 't>, parser: &mut P)
412412
-> Result<<P as AtRuleParser<'i>>::AtRule, PreciseParseError<'i, E>>
413413
where P: AtRuleParser<'i, Error = E> {

src/size_of_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use compact_cow_str::CompactCowStr;
5+
use compact_cow_str::CowRcStr;
66
use std::borrow::Cow;
77
use tokenizer::Token;
88

@@ -34,4 +34,4 @@ macro_rules! size_of_test {
3434
// These assume 64-bit
3535
size_of_test!(token, Token, 32);
3636
size_of_test!(std_cow_str, Cow<'static, str>, 32);
37-
size_of_test!(compact_cow_str, CompactCowStr, 16);
37+
size_of_test!(compact_cow_str, CowRcStr, 16);

src/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::{Parser, Delimiter, Token, SourceLocation, ParseError,
1616
AtRuleType, AtRuleParser, QualifiedRuleParser, ParserInput,
1717
parse_one_declaration, parse_one_rule, parse_important,
1818
stylesheet_encoding, EncodingSupport,
19-
TokenSerializationType, CompactCowStr,
19+
TokenSerializationType, CowRcStr,
2020
Color, RGBA, parse_nth, UnicodeRange, ToCss};
2121

2222
macro_rules! JArray {
@@ -294,7 +294,7 @@ fn unquoted_url_escaping() {
294294

295295
#[test]
296296
fn test_expect_url() {
297-
fn parse<'a>(s: &mut ParserInput<'a>) -> Result<CompactCowStr<'a>, BasicParseError<'a>> {
297+
fn parse<'a>(s: &mut ParserInput<'a>) -> Result<CowRcStr<'a>, BasicParseError<'a>> {
298298
Parser::new(s).expect_url()
299299
}
300300
let mut input = ParserInput::new("url()");
@@ -678,7 +678,7 @@ impl<'i> DeclarationParser<'i> for JsonParser {
678678
type Declaration = Json;
679679
type Error = ();
680680

681-
fn parse_value<'t>(&mut self, name: CompactCowStr<'i>, input: &mut Parser<'i, 't>)
681+
fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
682682
-> Result<Json, ParseError<'i, ()>> {
683683
let mut value = vec![];
684684
let mut important = false;
@@ -719,7 +719,7 @@ impl<'i> AtRuleParser<'i> for JsonParser {
719719
type AtRule = Json;
720720
type Error = ();
721721

722-
fn parse_prelude<'t>(&mut self, name: CompactCowStr<'i>, input: &mut Parser<'i, 't>)
722+
fn parse_prelude<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
723723
-> Result<AtRuleType<Vec<Json>, Json>, ParseError<'i, ()>> {
724724
Ok(AtRuleType::OptionalBlock(vec![
725725
"at-rule".to_json(),

0 commit comments

Comments
 (0)