removed languages.json and territories.json
Some checks failed
Build Zenyx ⚡ / 🧪 Run Cargo Tests (pull_request) Failing after 6m9s
Build Zenyx ⚡ / 🏗️ Build aarch64-apple-darwin (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build aarch64-pc-windows-msvc (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-apple-darwin (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (pull_request) Has been skipped
Some checks failed
Build Zenyx ⚡ / 🧪 Run Cargo Tests (pull_request) Failing after 6m9s
Build Zenyx ⚡ / 🏗️ Build aarch64-apple-darwin (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build aarch64-pc-windows-msvc (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build aarch64-unknown-linux-gnu (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-apple-darwin (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-pc-windows-msvc (pull_request) Has been skipped
Build Zenyx ⚡ / 🏗️ Build x86_64-unknown-linux-gnu (pull_request) Has been skipped
lib.rs is separated into src/modules now for cleaner code optimized error handling to -> (storage.rs, uptime.rs, meta.rs, memory.rs, os.rs, network.rs) optimized struct types to -> (storage.rs, uptime.rs, meta.rs, memory.rs, os.rs, network.rs)
This commit is contained in:
parent
91c80d0f91
commit
528d4b03a3
28 changed files with 1261 additions and 1726 deletions
55
subcrates/telemetry/src/modules/formatted/architecture.rs
Normal file
55
subcrates/telemetry/src/modules/formatted/architecture.rs
Normal file
|
@ -0,0 +1,55 @@
|
|||
use serde::Serialize;
|
||||
use std::{
|
||||
fmt::{Debug, Display, Formatter, Result as FmtResult},
|
||||
ops::Deref,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Serialize)]
|
||||
pub enum TargetPointerWidth {
|
||||
W32Bit,
|
||||
W64Bit,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct FmtOSArchitecture(pub TargetPointerWidth);
|
||||
|
||||
impl FmtOSArchitecture {
|
||||
pub const W32_BIT: Self = FmtOSArchitecture(TargetPointerWidth::W32Bit);
|
||||
pub const W64_BIT: Self = FmtOSArchitecture(TargetPointerWidth::W64Bit);
|
||||
}
|
||||
|
||||
impl Display for FmtOSArchitecture {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match self.0 {
|
||||
TargetPointerWidth::W32Bit => "32 Bit",
|
||||
TargetPointerWidth::W64Bit => "64 Bit",
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for FmtOSArchitecture {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for FmtOSArchitecture {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for FmtOSArchitecture {
|
||||
type Target = TargetPointerWidth;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
38
subcrates/telemetry/src/modules/formatted/bytes.rs
Normal file
38
subcrates/telemetry/src/modules/formatted/bytes.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use serde::Serialize;
|
||||
use std::{
|
||||
fmt::{Debug, Display, Formatter, Result as FmtResult},
|
||||
ops::Deref,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct FmtBytes(pub u64);
|
||||
|
||||
impl Display for FmtBytes {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
use humansize::{DECIMAL, format_size};
|
||||
write!(f, "{}", format_size(self.0, DECIMAL))
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for FmtBytes {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for FmtBytes {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for FmtBytes {
|
||||
type Target = u64;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
125
subcrates/telemetry/src/modules/formatted/date_time.rs
Normal file
125
subcrates/telemetry/src/modules/formatted/date_time.rs
Normal file
|
@ -0,0 +1,125 @@
|
|||
use chrono::{DateTime, Local, TimeZone, Utc};
|
||||
use serde::Serialize;
|
||||
use std::{
|
||||
fmt::{Debug, Display, Formatter, Result as FMTResult},
|
||||
ops::Deref,
|
||||
};
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct DateTimeInfo {
|
||||
date: String,
|
||||
time: String,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct FmtDateTime<Tz: TimeZone>(pub DateTime<Tz>);
|
||||
|
||||
impl<Tz: TimeZone> Display for FmtDateTime<Tz>
|
||||
where
|
||||
Tz: TimeZone,
|
||||
Tz::Offset: std::fmt::Display,
|
||||
{
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FMTResult {
|
||||
write!(
|
||||
f,
|
||||
"{:#?}",
|
||||
DateTimeInfo {
|
||||
date: self.0.format("%Y-%m-%d").to_string(),
|
||||
time: self.0.format("%H:%M:%S").to_string()
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Tz: TimeZone> Debug for FmtDateTime<Tz>
|
||||
where
|
||||
Tz::Offset: std::fmt::Display,
|
||||
{
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FMTResult {
|
||||
Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl<Tz: TimeZone> Serialize for FmtDateTime<Tz>
|
||||
where
|
||||
DateTime<Tz>: Display,
|
||||
{
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl<Tz: TimeZone> Deref for FmtDateTime<Tz> {
|
||||
type Target = DateTime<Tz>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<Tz: TimeZone> Eq for FmtDateTime<Tz> where DateTime<Tz>: Eq {}
|
||||
impl<Tz: TimeZone> PartialEq for FmtDateTime<Tz>
|
||||
where
|
||||
DateTime<Tz>: PartialEq,
|
||||
{
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0 == other.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<Tz: TimeZone> PartialOrd for FmtDateTime<Tz>
|
||||
where
|
||||
DateTime<Tz>: PartialOrd,
|
||||
{
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl<Tz: TimeZone> Ord for FmtDateTime<Tz>
|
||||
where
|
||||
DateTime<Tz>: Ord,
|
||||
{
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
self.0.cmp(&other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FmtDateTime<Utc>> for FmtDateTime<Local> {
|
||||
fn from(dt: FmtDateTime<Utc>) -> Self {
|
||||
FmtDateTime(dt.0.with_timezone(&Local))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<FmtDateTime<Local>> for FmtDateTime<Utc> {
|
||||
fn from(dt: FmtDateTime<Local>) -> Self {
|
||||
FmtDateTime(dt.0.with_timezone(&Utc))
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub trait IntoDateTime {
|
||||
fn into_utc(self) -> FmtDateTime<Utc>;
|
||||
fn into_local(self) -> FmtDateTime<Local>;
|
||||
}
|
||||
|
||||
impl IntoDateTime for FmtDateTime<Local> {
|
||||
fn into_utc(self) -> FmtDateTime<Utc> {
|
||||
FmtDateTime(self.0.with_timezone(&Utc))
|
||||
}
|
||||
fn into_local(self) -> FmtDateTime<Local> {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoDateTime for FmtDateTime<Utc> {
|
||||
fn into_local(self) -> FmtDateTime<Local> {
|
||||
FmtDateTime(self.0.with_timezone(&Local))
|
||||
}
|
||||
fn into_utc(self) -> FmtDateTime<Utc> {
|
||||
self
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
use detect_desktop_environment::DesktopEnvironment;
|
||||
use serde::{Serialize, Serializer};
|
||||
use std::{
|
||||
fmt::{Debug, Display, Formatter, Result as FmtResult},
|
||||
ops::Deref,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct SerdeDE(pub DesktopEnvironment);
|
||||
|
||||
impl Serialize for SerdeDE {
|
||||
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
serializer.serialize_str(&format!("{:?}", self.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl SerdeDE {
|
||||
pub fn detect() -> Option<Self> {
|
||||
DesktopEnvironment::detect().map(SerdeDE)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq)]
|
||||
pub struct FmtDE(pub SerdeDE);
|
||||
|
||||
impl FmtDE {
|
||||
pub fn detect() -> Option<Self> {
|
||||
SerdeDE::detect().map(FmtDE)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for FmtDE {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "{:?}", self.0.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for FmtDE {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for FmtDE {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for FmtDE {
|
||||
type Target = SerdeDE;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
7
subcrates/telemetry/src/modules/formatted/mod.rs
Normal file
7
subcrates/telemetry/src/modules/formatted/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
pub mod architecture;
|
||||
pub mod bytes;
|
||||
pub mod date_time;
|
||||
pub mod desktop_environment;
|
||||
pub mod offset_time;
|
||||
pub mod relative_time;
|
||||
pub mod version;
|
68
subcrates/telemetry/src/modules/formatted/offset_time.rs
Normal file
68
subcrates/telemetry/src/modules/formatted/offset_time.rs
Normal file
|
@ -0,0 +1,68 @@
|
|||
use chrono::{DateTime, Local, Offset};
|
||||
use serde::Serialize;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
fmt::{Debug, Display, Formatter, Result as FmtResult},
|
||||
ops::Deref,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct FmtOffsetTime(pub DateTime<Local>);
|
||||
|
||||
impl Display for FmtOffsetTime {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "UTC{}", self.0.offset())
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for FmtOffsetTime {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for FmtOffsetTime {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for FmtOffsetTime {
|
||||
type Target = DateTime<Local>;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for FmtOffsetTime {}
|
||||
impl PartialEq for FmtOffsetTime {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.0.offset().fix() == other.0.offset().fix()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for FmtOffsetTime {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(
|
||||
self.0
|
||||
.offset()
|
||||
.fix()
|
||||
.local_minus_utc()
|
||||
.cmp(&other.0.offset().fix().local_minus_utc()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for FmtOffsetTime {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.0
|
||||
.offset()
|
||||
.fix()
|
||||
.local_minus_utc()
|
||||
.cmp(&other.0.offset().fix().local_minus_utc())
|
||||
}
|
||||
}
|
40
subcrates/telemetry/src/modules/formatted/relative_time.rs
Normal file
40
subcrates/telemetry/src/modules/formatted/relative_time.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
use serde::Serialize;
|
||||
use std::{
|
||||
fmt::{Debug, Display, Formatter, Result as FmtResult},
|
||||
ops::Deref,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct FmtRelativeTime(pub Duration);
|
||||
|
||||
impl Display for FmtRelativeTime {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
let formatter = timeago::Formatter::new();
|
||||
|
||||
write!(f, "{}", formatter.convert(self.0))
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for FmtRelativeTime {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for FmtRelativeTime {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for FmtRelativeTime {
|
||||
type Target = Duration;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
38
subcrates/telemetry/src/modules/formatted/version.rs
Normal file
38
subcrates/telemetry/src/modules/formatted/version.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use serde::Serialize;
|
||||
use std::{
|
||||
fmt::{Debug, Display, Formatter, Result as FmtResult},
|
||||
ops::Deref,
|
||||
};
|
||||
use versions::Versioning;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct FmtVersion(pub Versioning);
|
||||
|
||||
impl Display for FmtVersion {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
write!(f, "{}", self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Debug for FmtVersion {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
Display::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for FmtVersion {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for FmtVersion {
|
||||
type Target = Versioning;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue