Skip to content

Commit 42ff747

Browse files
committed
Mark various constructors const
1 parent 37fe2cd commit 42ff747

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

color/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ pub struct Hsl {
572572

573573
impl Hsl {
574574
/// Construct a new HSL color from it's components.
575-
pub fn new(
575+
pub const fn new(
576576
hue: Option<f32>,
577577
saturation: Option<f32>,
578578
lightness: Option<f32>,
@@ -619,7 +619,7 @@ pub struct Hwb {
619619

620620
impl Hwb {
621621
/// Construct a new HWB color from it's components.
622-
pub fn new(
622+
pub const fn new(
623623
hue: Option<f32>,
624624
whiteness: Option<f32>,
625625
blackness: Option<f32>,
@@ -685,7 +685,7 @@ macro_rules! impl_lab_like {
685685
($cls:ident, $fname:literal) => {
686686
impl $cls {
687687
/// Construct a new Lab color format with lightness, a, b and alpha components.
688-
pub fn new(
688+
pub const fn new(
689689
lightness: Option<f32>,
690690
a: Option<f32>,
691691
b: Option<f32>,
@@ -757,7 +757,7 @@ macro_rules! impl_lch_like {
757757
($cls:ident, $fname:literal) => {
758758
impl $cls {
759759
/// Construct a new color with lightness, chroma and hue components.
760-
pub fn new(
760+
pub const fn new(
761761
lightness: Option<f32>,
762762
chroma: Option<f32>,
763763
hue: Option<f32>,
@@ -814,7 +814,7 @@ pub struct ColorFunction {
814814
impl ColorFunction {
815815
/// Construct a new color function definition with the given color space and
816816
/// color components.
817-
pub fn new(
817+
pub const fn new(
818818
color_space: PredefinedColorSpace,
819819
c1: Option<f32>,
820820
c2: Option<f32>,

src/parser.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,13 @@ impl<'i, T> From<BasicParseError<'i>> for ParseError<'i, T> {
116116
impl SourceLocation {
117117
/// Create a new BasicParseError at this location for an unexpected token
118118
#[inline]
119-
pub fn new_basic_unexpected_token_error(self, token: Token<'_>) -> BasicParseError<'_> {
119+
pub const fn new_basic_unexpected_token_error(self, token: Token<'_>) -> BasicParseError<'_> {
120120
self.new_basic_error(BasicParseErrorKind::UnexpectedToken(token))
121121
}
122122

123123
/// Create a new BasicParseError at this location
124124
#[inline]
125-
pub fn new_basic_error(self, kind: BasicParseErrorKind<'_>) -> BasicParseError<'_> {
125+
pub const fn new_basic_error(self, kind: BasicParseErrorKind<'_>) -> BasicParseError<'_> {
126126
BasicParseError {
127127
kind,
128128
location: self,
@@ -131,13 +131,13 @@ impl SourceLocation {
131131

132132
/// Create a new ParseError at this location for an unexpected token
133133
#[inline]
134-
pub fn new_unexpected_token_error<E>(self, token: Token<'_>) -> ParseError<'_, E> {
134+
pub const fn new_unexpected_token_error<E>(self, token: Token<'_>) -> ParseError<'_, E> {
135135
self.new_error(BasicParseErrorKind::UnexpectedToken(token))
136136
}
137137

138138
/// Create a new basic ParseError at the current location
139139
#[inline]
140-
pub fn new_error<E>(self, kind: BasicParseErrorKind<'_>) -> ParseError<'_, E> {
140+
pub const fn new_error<E>(self, kind: BasicParseErrorKind<'_>) -> ParseError<'_, E> {
141141
ParseError {
142142
kind: ParseErrorKind::Basic(kind),
143143
location: self,
@@ -240,7 +240,7 @@ struct CachedToken<'i> {
240240

241241
impl<'i> ParserInput<'i> {
242242
/// Create a new input for a parser.
243-
pub fn new(input: &'i str) -> ParserInput<'i> {
243+
pub const fn new(input: &'i str) -> ParserInput<'i> {
244244
ParserInput {
245245
tokenizer: Tokenizer::new(input),
246246
cached_token: None,
@@ -383,7 +383,7 @@ macro_rules! expect {
383383
impl<'i: 't, 't> Parser<'i, 't> {
384384
/// Create a new parser
385385
#[inline]
386-
pub fn new(input: &'t mut ParserInput<'i>) -> Parser<'i, 't> {
386+
pub const fn new(input: &'t mut ParserInput<'i>) -> Parser<'i, 't> {
387387
Parser {
388388
input,
389389
at_start_of: None,
@@ -435,7 +435,7 @@ impl<'i: 't, 't> Parser<'i, 't> {
435435

436436
/// The current line number and column number.
437437
#[inline]
438-
pub fn current_source_location(&self) -> SourceLocation {
438+
pub const fn current_source_location(&self) -> SourceLocation {
439439
self.input.tokenizer.current_source_location()
440440
}
441441

@@ -459,13 +459,13 @@ impl<'i: 't, 't> Parser<'i, 't> {
459459

460460
/// Create a new BasicParseError at the current location
461461
#[inline]
462-
pub fn new_basic_error(&self, kind: BasicParseErrorKind<'i>) -> BasicParseError<'i> {
462+
pub const fn new_basic_error(&self, kind: BasicParseErrorKind<'i>) -> BasicParseError<'i> {
463463
self.current_source_location().new_basic_error(kind)
464464
}
465465

466466
/// Create a new basic ParseError at the current location
467467
#[inline]
468-
pub fn new_error<E>(&self, kind: BasicParseErrorKind<'i>) -> ParseError<'i, E> {
468+
pub const fn new_error<E>(&self, kind: BasicParseErrorKind<'i>) -> ParseError<'i, E> {
469469
self.current_source_location().new_error(kind)
470470
}
471471

@@ -477,13 +477,13 @@ impl<'i: 't, 't> Parser<'i, 't> {
477477

478478
/// Create a new unexpected token BasicParseError at the current location
479479
#[inline]
480-
pub fn new_basic_unexpected_token_error(&self, token: Token<'i>) -> BasicParseError<'i> {
480+
pub const fn new_basic_unexpected_token_error(&self, token: Token<'i>) -> BasicParseError<'i> {
481481
self.new_basic_error(BasicParseErrorKind::UnexpectedToken(token))
482482
}
483483

484484
/// Create a new unexpected token ParseError at the current location
485485
#[inline]
486-
pub fn new_unexpected_token_error<E>(&self, token: Token<'i>) -> ParseError<'i, E> {
486+
pub const fn new_unexpected_token_error<E>(&self, token: Token<'i>) -> ParseError<'i, E> {
487487
self.new_error(BasicParseErrorKind::UnexpectedToken(token))
488488
}
489489

src/rules_and_declarations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl<'i, 't, 'a, P, I, E> RuleBodyParser<'i, 't, 'a, P, I, E> {
232232
/// The return type for finished declarations and at-rules also needs to be the same,
233233
/// since `<DeclarationListParser as Iterator>::next` can return either.
234234
/// It could be a custom enum.
235-
pub fn new(input: &'a mut Parser<'i, 't>, parser: &'a mut P) -> Self {
235+
pub const fn new(input: &'a mut Parser<'i, 't>, parser: &'a mut P) -> Self {
236236
Self {
237237
input,
238238
parser,
@@ -340,7 +340,7 @@ where
340340
///
341341
/// The return type for finished qualified rules and at-rules also needs to be the same,
342342
/// since `<RuleListParser as Iterator>::next` can return either. It could be a custom enum.
343-
pub fn new(input: &'a mut Parser<'i, 't>, parser: &'a mut P) -> Self {
343+
pub const fn new(input: &'a mut Parser<'i, 't>, parser: &'a mut P) -> Self {
344344
Self {
345345
input,
346346
parser,

src/serializer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ where
306306
W: fmt::Write,
307307
{
308308
/// Wrap a text writer to create a `CssStringWriter`.
309-
pub fn new(inner: &'a mut W) -> CssStringWriter<'a, W> {
309+
pub const fn new(inner: &'a mut W) -> CssStringWriter<'a, W> {
310310
CssStringWriter { inner }
311311
}
312312
}

src/tokenizer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ enum SeenStatus {
229229

230230
impl<'a> Tokenizer<'a> {
231231
#[inline]
232-
pub fn new(input: &'a str) -> Self {
232+
pub const fn new(input: &'a str) -> Self {
233233
Tokenizer {
234234
input,
235235
position: 0,
@@ -274,7 +274,7 @@ impl<'a> Tokenizer<'a> {
274274
}
275275

276276
#[inline]
277-
pub fn current_source_location(&self) -> SourceLocation {
277+
pub const fn current_source_location(&self) -> SourceLocation {
278278
SourceLocation {
279279
line: self.current_line_number,
280280
column: (self.position - self.current_line_start_position + 1) as u32,

0 commit comments

Comments
 (0)