Split format_table into separate crate and reduce k2v-client dependencies

This commit is contained in:
Alex Auvolat
2023-05-17 13:01:37 +02:00
parent b66f247580
commit a1cec2cd60
14 changed files with 102 additions and 47 deletions
+12
View File
@@ -0,0 +1,12 @@
[package]
name = "format_table"
version = "0.1.0"
authors = ["Alex Auvolat <alex@adnab.me>"]
edition = "2018"
license = "AGPL-3.0"
description = "Format tables with a stupid API"
repository = "https://git.deuxfleurs.fr/Deuxfleurs/garage"
readme = "README.md"
[lib]
path = "lib.rs"
+13
View File
@@ -0,0 +1,13 @@
# `format_table`
Format tables with a stupid API. [Documentation](https://docs.rs/format_table).
Example:
```rust
let mut table = vec!["product\tquantity\tprice".to_string()];
for (p, q, r) in [("tomato", 12, 15), ("potato", 10, 20), ("rice", 5, 12)] {
table.push(format!("{}\t{}\t{}", p, q, r));
}
format_table::format_table(table);
```
@@ -1,3 +1,19 @@
//! Format tables with a stupid API.
//!
//! Example:
//!
//! ```rust
//! let mut table = vec!["product\tquantity\tprice".to_string()];
//! for (p, q, r) in [("tomato", 12, 15), ("potato", 10, 20), ("rice", 5, 12)] {
//! table.push(format!("{}\t{}\t{}", p, q, r));
//! }
//! format_table::format_table(table);
//! ```
//!
//! A table to be formatted is a `Vec<String>`, containing one string per line.
//! Table columns in each line are separated by a `\t` character.
/// Format a table and return the result as a string.
pub fn format_table_to_string(data: Vec<String>) -> String {
let data = data
.iter()
@@ -27,6 +43,7 @@ pub fn format_table_to_string(data: Vec<String>) -> String {
out
}
/// Format a table and print the result to stdout.
pub fn format_table(data: Vec<String>) {
print!("{}", format_table_to_string(data));
}
+1
View File
@@ -21,6 +21,7 @@ path = "tests/lib.rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
format_table.workspace = true
garage_db.workspace = true
garage_api.workspace = true
garage_block.workspace = true
+1 -1
View File
@@ -5,11 +5,11 @@ use std::sync::Arc;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use format_table::format_table_to_string;
use garage_util::background::BackgroundRunner;
use garage_util::crdt::*;
use garage_util::data::*;
use garage_util::error::Error as GarageError;
use garage_util::formater::format_table_to_string;
use garage_util::time::*;
use garage_table::replication::*;
+1 -1
View File
@@ -1,8 +1,8 @@
use std::collections::HashSet;
use std::time::Duration;
use format_table::format_table;
use garage_util::error::*;
use garage_util::formater::format_table;
use garage_rpc::layout::*;
use garage_rpc::system::*;
+1 -1
View File
@@ -1,6 +1,6 @@
use format_table::format_table;
use garage_util::crdt::Crdt;
use garage_util::error::*;
use garage_util::formater::format_table;
use garage_rpc::layout::*;
use garage_rpc::system::*;
+1 -1
View File
@@ -1,11 +1,11 @@
use std::collections::HashMap;
use std::time::Duration;
use format_table::format_table;
use garage_util::background::*;
use garage_util::crdt::*;
use garage_util::data::*;
use garage_util::error::*;
use garage_util::formater::format_table;
use garage_util::time::*;
use garage_block::manager::BlockResyncErrorInfo;
+2 -3
View File
@@ -23,12 +23,11 @@ tokio = { version = "1.0", default-features = false, features = ["rt", "rt-multi
# cli deps
clap = { version = "4.1", optional = true, features = ["derive", "env"] }
garage_util = { workspace = true, optional = true }
garage_db = { workspace = true, optional = true }
format_table = { workspace = true, optional = true }
[features]
cli = ["clap", "tokio/fs", "tokio/io-std", "garage_util", "garage_db/sled"]
cli = ["clap", "tokio/fs", "tokio/io-std", "format_table"]
[lib]
path = "lib.rs"
+1 -1
View File
@@ -6,7 +6,7 @@ use base64::prelude::*;
use k2v_client::*;
use garage_util::formater::format_table;
use format_table::format_table;
use rusoto_core::credential::AwsCredentials;
use rusoto_core::Region;
-1
View File
@@ -10,7 +10,6 @@ pub mod crdt;
pub mod data;
pub mod encode;
pub mod error;
pub mod formater;
pub mod forwarded_headers;
pub mod metrics;
pub mod migrate;