Use traits to keep things private

This commit is contained in:
Wojciech Kozlowski 2023-03-30 23:42:48 +09:00
parent d5572644ee
commit dae9ed791e

View File

@ -4,11 +4,15 @@ use crate::{Album, Track};
use super::{Error, Library, Query, QueryOption};
pub trait SimpleOption {}
trait QueryOptionArgBeets {
fn to_arg(&self, option_name: &str) -> Option<String>;
}
trait SimpleOption {}
impl SimpleOption for String {}
impl SimpleOption for u32 {}
impl<T: SimpleOption + Display> QueryOption<T> {
impl<T: SimpleOption + Display> QueryOptionArgBeets for QueryOption<T> {
fn to_arg(&self, option_name: &str) -> Option<String> {
let (negate, value) = match self {
Self::Include(value) => ("", value),
@ -19,7 +23,7 @@ impl<T: SimpleOption + Display> QueryOption<T> {
}
}
impl QueryOption<Vec<String>> {
impl QueryOptionArgBeets for QueryOption<Vec<String>> {
fn to_arg(&self, option_name: &str) -> Option<String> {
let (negate, vec) = match self {
Self::Include(value) => ("", value),
@ -30,7 +34,11 @@ impl QueryOption<Vec<String>> {
}
}
impl Query {
trait QueryArgsBeets {
fn to_args(&self) -> Vec<String>;
}
impl QueryArgsBeets for Query {
fn to_args(&self) -> Vec<String> {
let mut arguments: Vec<String> = vec![];