Skip to content

Commit

Permalink
enhance: show upper name
Browse files Browse the repository at this point in the history
  • Loading branch information
kingwingfly committed Sep 5, 2024
1 parent e8ec11e commit 6921449
Show file tree
Hide file tree
Showing 14 changed files with 119 additions and 49 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
-->

## [Unreleased]
## [0.2.33] - 2024-09-05

- fav status will show name of resource creator.
- enhance: Owner trait for resource.

## [0.2.32] - 2024-08-21

- fix: `fav pull <res_id>` will now forcely pull the resource.
Expand Down
58 changes: 29 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[workspace.package]
version = "0.2.32"
version = "0.2.33"
authors = ["Louis <[email protected]>"]
description = "Back up your favorite online resources with CLI."
license = "MIT"
Expand All @@ -14,10 +14,10 @@ repository = "https://github.com/kingwingfly/fav"
documentation = ""

[workspace.dependencies]
fav_core = { path = "fav_core", version = "0.1.4" }
fav_derive = { path = "fav_derive", version = "0.0.2" }
fav_utils = { path = "fav_utils", version = "0.0.13" }
fav_cli = { path = "fav_cli", version = "0.2.32" }
fav_core = { path = "fav_core", version = "0.1.5" }
fav_derive = { path = "fav_derive", version = "0.0.3" }
fav_utils = { path = "fav_utils", version = "0.0.14" }
fav_cli = { path = "fav_cli", version = "0.2.33" }

[profile.release]
lto = "fat"
Expand Down
2 changes: 1 addition & 1 deletion fav_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fav_core"
version = "0.1.4"
version = "0.1.5"
authors.workspace = true
description = "Fav's core crate; A collection of traits."
license.workspace = true
Expand Down
8 changes: 7 additions & 1 deletion fav_core/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::fmt::Display;

#[cfg(feature = "derive")]
pub use fav_derive::Attr;
pub use fav_derive::{Attr, Owner};

/// The resource's id.
/// # Example
Expand Down Expand Up @@ -87,6 +87,12 @@ pub trait Count {
fn count(&self) -> i32;
}

/// The resource's owner
pub trait Owner {
/// Return the owner of the resource
fn owner(&self) -> &str;
}

impl From<i64> for Id<'_> {
fn from(id: i64) -> Self {
Id::I64(id)
Expand Down
2 changes: 1 addition & 1 deletion fav_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub use error::*;
/// Re-export the most important traits and types
pub mod prelude {
pub use crate::api::{Api, ApiProvider};
pub use crate::attr::{Attr, Count, Id};
pub use crate::attr::{Attr, Count, Id, Owner};
pub use crate::config::{Config, HttpConfig};
pub use crate::error::*;
pub use crate::local::{PathInfo, ProtoLocal, SaveLocal};
Expand Down
6 changes: 3 additions & 3 deletions fav_core/src/meta.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Meta,
//! making resource completely able to be operated
use crate::{attr::Attr, status::Status};
use crate::{attr::{Attr, Owner}, status::Status};

/// Making resource has the complete metadata needed
/// This is an auto trait for `T: Attr + Status`.
/// See [`Attr`] and [`Status`].
pub trait Meta: Attr + Status {}
pub trait Meta: Attr + Owner + Status {}

impl<T: Attr + Status> Meta for T {}
impl<T: Attr + Owner + Status> Meta for T {}
6 changes: 6 additions & 0 deletions fav_core/src/test_utils/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ impl Attr for TestRes {
}
}

impl Owner for TestRes {
fn owner(&self) -> &str {
todo!()
}
}

impl Status for TestRes {
fn status(&self) -> i32 {
self.status
Expand Down
14 changes: 8 additions & 6 deletions fav_core/src/visual.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Data visualize
use crate::attr::{Attr, Count};
use crate::attr::{Attr, Count, Owner};
use crate::res::{Res, Set, Sets};
use crate::status::{Status, StatusFlags};
use tabled::{
Expand Down Expand Up @@ -44,16 +44,17 @@ where
impl<T> TableSet for T
where
T: Set,
T::Res: Attr + Status,
T::Res: Attr + Status + Owner,
{
fn table(&self) {
let header = vec!["ID", "Title", "Track", "Saved"];
let header = vec!["ID", "Upper", "Title", "Track", "Saved"];
let rows = self.iter().map(|res| {
let id = String::from(res.id());
let upper = res.owner().to_string().chars().take(15).collect();
let title = res.title().to_string().chars().take(15).collect();
let track = res.check_status(StatusFlags::TRACK).to_string();
let saved = res.check_status(StatusFlags::SAVED).to_string();
vec![id, title, track, saved]
vec![id, upper, title, track, saved]
});
show_table(header, rows);
}
Expand All @@ -64,13 +65,14 @@ where
T: Res,
{
fn table(&self) {
let header = vec!["ID", "Title", "Track", "Saved", "Expired"];
let header = vec!["ID", "Upper", "Title", "Track", "Saved", "Expired"];
let id = String::from(self.id());
let upper = self.owner().to_string().chars().take(15).collect();
let title = self.title().to_string().chars().take(15).collect();
let track = self.check_status(StatusFlags::TRACK).to_string();
let saved = self.check_status(StatusFlags::SAVED).to_string();
let expired = self.check_status(StatusFlags::EXPIRED).to_string();
let rows = vec![vec![id, title, track, saved, expired]];
let rows = vec![vec![id, upper, title, track, saved, expired]];
show_table(header, rows);
}
}
Expand Down
2 changes: 1 addition & 1 deletion fav_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fav_derive"
version = "0.0.2"
version = "0.0.3"
authors.workspace = true
description = "Derive macros for fav"
license.workspace = true
Expand Down
7 changes: 7 additions & 0 deletions fav_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use proc_macro::TokenStream;

mod api;
mod attr;
mod owner;
mod status;

/// A derive macro helping implemente [`Api`] trait.
Expand Down Expand Up @@ -79,3 +80,9 @@ pub fn derive_attr(input: TokenStream) -> TokenStream {
pub fn derive_status(input: TokenStream) -> TokenStream {
status::derive_status(input)
}

/// A derive macro helping implemente [`Owner`] trait.
#[proc_macro_derive(Owner, attributes(owner))]
pub fn derive_owner(input: TokenStream) -> TokenStream {
owner::derive_owner(input)
}
Loading

0 comments on commit 6921449

Please sign in to comment.