Use #[must_use] pub const fn new(...) whenever possible

This commit is contained in:
Uwe Klotz 2023-01-11 00:17:56 +01:00 committed by Alex
parent f73783aa8a
commit dca773401d
9 changed files with 37 additions and 19 deletions

View file

@ -21,7 +21,13 @@ pub struct PageHeader {
impl PageHeader { impl PageHeader {
/// Creates a new `PageHeader` /// Creates a new `PageHeader`
pub fn new(header_type_flag: u8, abgp: u64, stream_serial: u32, sequence_number: u32) -> Self { #[must_use]
pub const fn new(
header_type_flag: u8,
abgp: u64,
stream_serial: u32,
sequence_number: u32,
) -> Self {
Self { Self {
start: 0, start: 0,
header_type_flag, header_type_flag,

View file

@ -122,7 +122,8 @@ pub struct ID3v2Error {
impl ID3v2Error { impl ID3v2Error {
/// Create a new `ID3v2Error` from an [`ID3v2ErrorKind`] /// Create a new `ID3v2Error` from an [`ID3v2ErrorKind`]
pub fn new(kind: ID3v2ErrorKind) -> Self { #[must_use]
pub const fn new(kind: ID3v2ErrorKind) -> Self {
Self { kind } Self { kind }
} }
@ -152,7 +153,8 @@ pub struct FileDecodingError {
impl FileDecodingError { impl FileDecodingError {
/// Create a `FileDecodingError` from a [`FileType`] and description /// Create a `FileDecodingError` from a [`FileType`] and description
pub fn new(format: FileType, description: &'static str) -> Self { #[must_use]
pub const fn new(format: FileType, description: &'static str) -> Self {
Self { Self {
format: Some(format), format: Some(format),
description, description,
@ -206,7 +208,8 @@ pub struct FileEncodingError {
impl FileEncodingError { impl FileEncodingError {
/// Create a `FileEncodingError` from a [`FileType`] and description /// Create a `FileEncodingError` from a [`FileType`] and description
pub fn new(format: FileType, description: &'static str) -> Self { #[must_use]
pub const fn new(format: FileType, description: &'static str) -> Self {
Self { Self {
format: Some(format), format: Some(format),
description, description,
@ -259,7 +262,8 @@ pub struct LoftyError {
impl LoftyError { impl LoftyError {
/// Create a `LoftyError` from an [`ErrorKind`] /// Create a `LoftyError` from an [`ErrorKind`]
pub fn new(kind: ErrorKind) -> Self { #[must_use]
pub const fn new(kind: ErrorKind) -> Self {
Self { kind } Self { kind }
} }

View file

@ -380,7 +380,8 @@ pub struct TaggedFile {
impl TaggedFile { impl TaggedFile {
#[doc(hidden)] #[doc(hidden)]
/// This exists for use in `lofty_attr`, there's no real use for this externally /// This exists for use in `lofty_attr`, there's no real use for this externally
pub fn new(ty: FileType, properties: FileProperties, tags: Vec<Tag>) -> Self { #[must_use]
pub const fn new(ty: FileType, properties: FileProperties, tags: Vec<Tag>) -> Self {
Self { Self {
ty, ty,
properties, properties,

View file

@ -18,7 +18,8 @@ where
} }
impl<B: ByteOrder> Chunks<B> { impl<B: ByteOrder> Chunks<B> {
pub fn new(file_size: u64) -> Self { #[must_use]
pub const fn new(file_size: u64) -> Self {
Self { Self {
fourcc: [0; 4], fourcc: [0; 4],
size: 0, size: 0,

View file

@ -87,7 +87,8 @@ pub struct Atom<'a> {
impl<'a> Atom<'a> { impl<'a> Atom<'a> {
/// Create a new [`Atom`] /// Create a new [`Atom`]
pub fn new(ident: AtomIdent<'a>, data: AtomData) -> Self { #[must_use]
pub const fn new(ident: AtomIdent<'a>, data: AtomData) -> Self {
Self { Self {
ident, ident,
data: AtomDataStorage::Single(data), data: AtomDataStorage::Single(data),

View file

@ -41,11 +41,7 @@ impl Default for ParseOptions {
/// } /// }
/// ``` /// ```
fn default() -> Self { fn default() -> Self {
Self { Self::new()
read_properties: true,
use_custom_resolvers: true,
parsing_mode: ParsingMode::Strict,
}
} }
} }
@ -61,8 +57,13 @@ impl ParseOptions {
/// ///
/// let parsing_options = ParseOptions::new(); /// let parsing_options = ParseOptions::new();
/// ``` /// ```
pub fn new() -> Self { #[must_use]
Self::default() pub const fn new() -> Self {
Self {
read_properties: true,
use_custom_resolvers: true,
parsing_mode: ParsingMode::Strict,
}
} }
/// Whether or not to read the audio properties /// Whether or not to read the audio properties
@ -206,7 +207,8 @@ impl<R: Read> Probe<R> {
/// let probe = Probe::new(reader); /// let probe = Probe::new(reader);
/// # Ok(()) } /// # Ok(()) }
/// ``` /// ```
pub fn new(reader: R) -> Self { #[must_use]
pub const fn new(reader: R) -> Self {
Self { Self {
inner: reader, inner: reader,
options: None, options: None,

View file

@ -27,7 +27,8 @@ impl Default for FileProperties {
impl FileProperties { impl FileProperties {
/// Create a new `FileProperties` /// Create a new `FileProperties`
pub fn new( #[must_use]
pub const fn new(
duration: Duration, duration: Duration,
overall_bitrate: Option<u32>, overall_bitrate: Option<u32>,
audio_bitrate: Option<u32>, audio_bitrate: Option<u32>,

View file

@ -660,7 +660,8 @@ impl TagItem {
} }
/// Create a new [`TagItem`] /// Create a new [`TagItem`]
pub fn new(item_key: ItemKey, item_value: ItemValue) -> Self { #[must_use]
pub const fn new(item_key: ItemKey, item_value: ItemValue) -> Self {
Self { Self {
item_key, item_key,
item_value, item_value,

View file

@ -225,7 +225,8 @@ impl Accessor for Tag {
impl Tag { impl Tag {
/// Initialize a new tag with a certain [`TagType`] /// Initialize a new tag with a certain [`TagType`]
pub fn new(tag_type: TagType) -> Self { #[must_use]
pub const fn new(tag_type: TagType) -> Self {
Self { Self {
tag_type, tag_type,
pictures: Vec::new(), pictures: Vec::new(),