Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derive PartiaEq & Eq and fix chrono deprecated warning #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::values::AllowedValues;
use crate::Result;

/// Sorting logic to apply after the update of storages.
#[derive(Debug, Clone, Copy, ToPrimitive)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, ToPrimitive)]
pub enum StorageSort {
/// Do not sort the storages
NotSorted = 0,
Expand All @@ -39,7 +39,7 @@ pub enum StorageSort {
/// whether there isn't enough information about the storage (`OnlyIds` where retrieved).
/// Note that `StoragePool` and `Storage` instances have knowledge about the result
/// of `update_storage`.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
pub enum UpdateResult {
/// No errors, everything went fine.
Success,
Expand All @@ -58,7 +58,7 @@ pub enum UpdateResult {
/// BatteryLevel::OnExternalPower => println!("Using external power, connected to AC"),
/// }
/// ```
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, PartialEq, Eq, Clone)]
pub enum BatteryLevel {
/// The device is currently on battery.
OnBattery(u8),
Expand Down
2 changes: 1 addition & 1 deletion src/device/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use num_derive::{FromPrimitive, ToPrimitive};

/// Supported `libmtp` device capabilities, you can test if an MTP device supports
/// one of those with [`MtpDevice::check_capability`](../struct.MtpDevice.html#method.check_capability)
#[derive(Debug, Clone, FromPrimitive, ToPrimitive)]
#[derive(Debug, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive)]
pub enum DeviceCapability {
/// This capability tells whether you can get partial objects.
GetPartialObject = 0,
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use thiserror::Error as ErrorTrait;

/// Enumeration of possible `libmtp` errors, check
/// [`Error::MtpError`](enum.Error.html#variant.MtpError) for more information.
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MtpErrorKind {
General,
PtpLayer,
Expand Down
2 changes: 1 addition & 1 deletion src/object/filetypes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::fmt::{self, Display};

/// Enumeration that holds the supported filetypes, this enum implements `Display`
/// with the description of the file type.
#[derive(Debug, Clone, FromPrimitive, ToPrimitive)]
#[derive(Debug, Clone, PartialEq, Eq, FromPrimitive, ToPrimitive)]
pub enum Filetype {
Folder = 0,
Wav,
Expand Down
2 changes: 1 addition & 1 deletion src/object/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::fmt::{self, Display};

/// Enumeration that holds the supported properties, this enum implements `Display` with the
/// description of the property.
#[derive(Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, ToPrimitive)]
pub enum Property {
StorageId = 0,
ObjectFormat,
Expand Down
8 changes: 4 additions & 4 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fn files_and_folders(mtpdev: &MtpDevice, storage_id: u32, parent: Parent) -> Vec

/// Represents the parent folder of an object, the top-most parent is called the "root" as in
/// *nix like systems.
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Parent {
Root,
Folder(u32),
Expand All @@ -71,7 +71,7 @@ impl Parent {
}
}

#[derive(Debug, Copy, Clone, FromPrimitive)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, FromPrimitive)]
pub enum StorageType {
Undefined = 0,
FixedRom,
Expand All @@ -80,15 +80,15 @@ pub enum StorageType {
RemovableRam,
}

#[derive(Debug, Copy, Clone, FromPrimitive)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, FromPrimitive)]
pub enum FilesystemType {
Undefined = 0,
GenericFlat,
GenericHierarchical,
DesignCameraFilesystem,
}

#[derive(Debug, Copy, Clone, FromPrimitive)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, FromPrimitive)]
pub enum AccessCapability {
ReadWrite = 0,
ReadOnly,
Expand Down
2 changes: 1 addition & 1 deletion src/storage/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl File<'_> {
/// Returns the latest modification date in UTC.
pub fn modification_date(&self) -> DateTime<Utc> {
let epoch = unsafe { (*self.inner).modificationdate };
Utc.timestamp(epoch, 0)
Utc.timestamp_opt(epoch, 0).unwrap()
}
Comment on lines 109 to 112
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to return the DateTime<Utc> wrapped inside Option so we avoid unwrap?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it would be, however, I wanted to do as little as possible changes to remove the deprecation. Chrono is doing unwrap() anyway.


/// Rename this file in-place.
Expand Down