Struct ApiClient

Source
pub struct ApiClient { /* private fields */ }
Expand description

Struct representing an API client

Implementations§

Source§

impl ApiClient

Source

pub async fn retrieve<T: Entity>(&self, entity_id: i32) -> Result<T>

This API lets you retrieve and view a specific entity by ID.

§Example
use anyhow::Result;
use rust_woocommerce::{Product, ApiClient, Config};
use tracing::info;

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let retrieved = client.retrieve::<Product>(12345).await?;
    info!("Retrieved product has sku: {}", retrieved.sku);
    Ok(())
}
Examples found in repository?
examples/customer.rs (line 12)
6
7
8
9
10
11
12
13
14
15
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let customers = client.list_all::<Customer>().await?;
    info!("Got {} customers", customers.len());
    let retrieved: Customer = client.retrieve(customers.first().unwrap().id).await?;
    info!("Retrieved customer name is {}", retrieved.first_name);
    Ok(())
}
More examples
Hide additional examples
examples/order.rs (line 14)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let orders = client.list_all::<Order>().await?;
    info!("Got {} orders", orders.len());
    let random_order_id = orders.first().ok_or(anyhow!("Error"))?.id;
    let retrieved_order = client.retrieve::<Order>(random_order_id).await?;
    info!(
        "Got order with number: {} with total: {}",
        retrieved_order.number, retrieved_order.total
    );
    Ok(())
}
examples/category.rs (line 13)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let categories = client.list_all::<Category>().await?;
    info!("Got {} categories", categories.len());
    let random_id = categories.first().unwrap().id;
    let retrieved: Category = client.retrieve(random_id).await?;
    info!("Retrieved category name: {}", retrieved.name);
    let create = Category::create("Test Category")
        .parent(retrieved.id)
        .description("Test description")
        .display(DisplayOption::Products)
        .image("https://woocommerce.github.io/woocommerce-rest-api-docs/images/logo-95f5c1ab.png");
    let batch_create = create.clone();
    let created: Category = client.create(create).await?;
    info!("Category with id: {} created", created.id);
    let update = Category::update().description("Some description");
    let updated: Category = client.update(created.id, update).await?;
    info!("New description is {}", updated.description);
    let deleted: Category = client.delete(updated.id).await?;
    info!("Category {} deleted", deleted.name);
    let batch_created: Vec<Category> = client.batch_create(vec![batch_create]).await?;
    info!("Batch created {} categories", batch_created.len());
    let batch_update = Category::update()
        .id(batch_created.first().unwrap().id)
        .description("Some description");
    let batch_updated: Vec<Category> = client.batch_update(vec![batch_update]).await?;
    let id = batch_updated.first().unwrap().id;
    info!("Batch updated categories contains category with id: {id}");
    let batch_deleted: Vec<Category> = client.batch_delete(vec![id]).await?;
    info!("Deleted {} categories", batch_deleted.len());
    Ok(())
}
examples/product.rs (line 18)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let start = std::time::Instant::now();
    let products = client.list_all::<Product>().await?;
    info!(
        "Got {} products in {} seconds",
        products.len(),
        start.elapsed().as_secs()
    );
    let random_id = products.first().map(|p| p.id).unwrap_or_default();
    let retrieved = client.retrieve::<Product>(random_id).await?;
    info!("Retrieved product has sku: {}", retrieved.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .visible()
        .build();
    let new_product = Product::builder()
        .name("Test Product For Example")
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let batch_create = vec![new_product.clone()];
    let created: Product = client.create(new_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);
    let update = Product::builder().unfeatured().build();
    let updated: Product = client.update(created.id, update).await?;
    info!(
        "Update product {}, new feature is {}",
        updated.name, updated.featured
    );
    let deleted: Product = client.delete(updated.id).await?;
    info!("Product {} deleted", deleted.name);
    let batch_created: Vec<Product> = client.batch_create(batch_create).await?;
    let id = batch_created.first().ok_or(anyhow!("Error"))?.id;
    let batch_update = Product::builder().id(id).unfeatured().build();
    let _batch_updated: Vec<Product> = client.batch_update(vec![batch_update]).await?;
    let _deleted: Product = client.delete(id).await?;
    Ok(())
}
Source

pub async fn list_all<T: Entity>(&self) -> Result<Vec<T>>

This API helps you to view all entities of type T.

§Example
use anyhow::Result;
use rust_woocommerce::{Product, ApiClient, Config};
use tracing::info;

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let products = client.list_all::<Product>().await?;
    info!("Got {} products", products.len());
    Ok(())
}
Examples found in repository?
examples/data.rs (line 9)
5
6
7
8
9
10
11
12
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let data = client.list_all::<Data>().await?;
    info!("Got {} data", data.len());
    Ok(())
}
More examples
Hide additional examples
examples/customer.rs (line 10)
6
7
8
9
10
11
12
13
14
15
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let customers = client.list_all::<Customer>().await?;
    info!("Got {} customers", customers.len());
    let retrieved: Customer = client.retrieve(customers.first().unwrap().id).await?;
    info!("Retrieved customer name is {}", retrieved.first_name);
    Ok(())
}
examples/order.rs (line 11)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let orders = client.list_all::<Order>().await?;
    info!("Got {} orders", orders.len());
    let random_order_id = orders.first().ok_or(anyhow!("Error"))?.id;
    let retrieved_order = client.retrieve::<Order>(random_order_id).await?;
    info!(
        "Got order with number: {} with total: {}",
        retrieved_order.number, retrieved_order.total
    );
    Ok(())
}
examples/category.rs (line 10)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let categories = client.list_all::<Category>().await?;
    info!("Got {} categories", categories.len());
    let random_id = categories.first().unwrap().id;
    let retrieved: Category = client.retrieve(random_id).await?;
    info!("Retrieved category name: {}", retrieved.name);
    let create = Category::create("Test Category")
        .parent(retrieved.id)
        .description("Test description")
        .display(DisplayOption::Products)
        .image("https://woocommerce.github.io/woocommerce-rest-api-docs/images/logo-95f5c1ab.png");
    let batch_create = create.clone();
    let created: Category = client.create(create).await?;
    info!("Category with id: {} created", created.id);
    let update = Category::update().description("Some description");
    let updated: Category = client.update(created.id, update).await?;
    info!("New description is {}", updated.description);
    let deleted: Category = client.delete(updated.id).await?;
    info!("Category {} deleted", deleted.name);
    let batch_created: Vec<Category> = client.batch_create(vec![batch_create]).await?;
    info!("Batch created {} categories", batch_created.len());
    let batch_update = Category::update()
        .id(batch_created.first().unwrap().id)
        .description("Some description");
    let batch_updated: Vec<Category> = client.batch_update(vec![batch_update]).await?;
    let id = batch_updated.first().unwrap().id;
    info!("Batch updated categories contains category with id: {id}");
    let batch_deleted: Vec<Category> = client.batch_delete(vec![id]).await?;
    info!("Deleted {} categories", batch_deleted.len());
    Ok(())
}
examples/product.rs (line 11)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let start = std::time::Instant::now();
    let products = client.list_all::<Product>().await?;
    info!(
        "Got {} products in {} seconds",
        products.len(),
        start.elapsed().as_secs()
    );
    let random_id = products.first().map(|p| p.id).unwrap_or_default();
    let retrieved = client.retrieve::<Product>(random_id).await?;
    info!("Retrieved product has sku: {}", retrieved.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .visible()
        .build();
    let new_product = Product::builder()
        .name("Test Product For Example")
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let batch_create = vec![new_product.clone()];
    let created: Product = client.create(new_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);
    let update = Product::builder().unfeatured().build();
    let updated: Product = client.update(created.id, update).await?;
    info!(
        "Update product {}, new feature is {}",
        updated.name, updated.featured
    );
    let deleted: Product = client.delete(updated.id).await?;
    info!("Product {} deleted", deleted.name);
    let batch_created: Vec<Product> = client.batch_create(batch_create).await?;
    let id = batch_created.first().ok_or(anyhow!("Error"))?.id;
    let batch_update = Product::builder().id(id).unfeatured().build();
    let _batch_updated: Vec<Product> = client.batch_update(vec![batch_update]).await?;
    let _deleted: Product = client.delete(id).await?;
    Ok(())
}
examples/variation.rs (line 14)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let products = client.list_all::<Product>().await?;
    let random_variable_id = products
        .iter()
        .find(|p| !p.variations.is_empty())
        .map(|p| p.id)
        .unwrap_or_default();
    let variations = client
        .list_all_subentities::<ProductVariation>(random_variable_id)
        .await?;
    info!(
        "Got {} variations for product with id: {random_variable_id}",
        variations.len()
    );
    let retrieved_variation: ProductVariation = client
        .retrieve_subentity(
            random_variable_id,
            variations.first().map(|v| v.id).unwrap_or_default(),
        )
        .await?;
    info!("Retrieved variation has sku: {}", retrieved_variation.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .option("Test")
        .variation()
        .visible()
        .build();
    let new_variable_product = Product::builder()
        .name("Test Product For Example")
        .product_type(ProductType::Variable)
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let created: Product = client.create(new_variable_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);

    let variation = ProductVariation::builder()
        .sku(format!("{} Best", created.sku))
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(96)
        .weight("52")
        .dimensions("5", "4", "3")
        .attribute(None, "Test Attribute", "Best")
        .build();
    let batch_create_variation = vec![variation.clone()];
    let created_variation: ProductVariation =
        client.create_subentity(created.id, variation).await?;
    info!(
        "Variation {} created with price: {}",
        created_variation.sku, created_variation.price
    );
    let update = ProductVariation::builder().regular_price("7000").build();
    let updated_variation: ProductVariation = client
        .update_subentity(created.id, created_variation.id, update)
        .await?;
    info!(
        "Variation {} updated with price: {}",
        updated_variation.sku, updated_variation.price
    );
    let deleted_variation: ProductVariation = client
        .delete_subentity(created.id, updated_variation.id)
        .await?;
    info!("Variation {} deleted", deleted_variation.sku);
    let batch_created_variation: Vec<ProductVariation> = client
        .batch_create_subentity(created.id, batch_create_variation)
        .await?;
    let bcv_id = batch_created_variation
        .first()
        .map(|v| v.id)
        .unwrap_or_default();
    let batch_update_variation = vec![ProductVariation::builder()
        .id(bcv_id)
        .regular_price("777")
        .build()];
    let _batch_updated_variation: Vec<ProductVariation> = client
        .batch_update_subentity(created.id, batch_update_variation)
        .await?;
    let _batch_deleted_variation: Vec<ProductVariation> = client
        .batch_delete_subentity(created.id, vec![bcv_id])
        .await?;
    let deleted: Product = client.delete(created.id).await?;
    info!("Product {} deleted", deleted.name);
    Ok(())
}
Source

pub async fn create<T: Entity>(&self, object: impl Serialize) -> Result<T>

This API helps you to create a new entity of type T.

§Example
use anyhow::Result;
use rust_woocommerce::{Product, ApiClient, Config, Attribute};
use tracing::info;

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .visible()
        .build();
    let new_product = Product::builder()
        .name("Test Product For Example")
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let created: Product = client.create(new_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);
    Ok(())
}
Examples found in repository?
examples/category.rs (line 21)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let categories = client.list_all::<Category>().await?;
    info!("Got {} categories", categories.len());
    let random_id = categories.first().unwrap().id;
    let retrieved: Category = client.retrieve(random_id).await?;
    info!("Retrieved category name: {}", retrieved.name);
    let create = Category::create("Test Category")
        .parent(retrieved.id)
        .description("Test description")
        .display(DisplayOption::Products)
        .image("https://woocommerce.github.io/woocommerce-rest-api-docs/images/logo-95f5c1ab.png");
    let batch_create = create.clone();
    let created: Category = client.create(create).await?;
    info!("Category with id: {} created", created.id);
    let update = Category::update().description("Some description");
    let updated: Category = client.update(created.id, update).await?;
    info!("New description is {}", updated.description);
    let deleted: Category = client.delete(updated.id).await?;
    info!("Category {} deleted", deleted.name);
    let batch_created: Vec<Category> = client.batch_create(vec![batch_create]).await?;
    info!("Batch created {} categories", batch_created.len());
    let batch_update = Category::update()
        .id(batch_created.first().unwrap().id)
        .description("Some description");
    let batch_updated: Vec<Category> = client.batch_update(vec![batch_update]).await?;
    let id = batch_updated.first().unwrap().id;
    info!("Batch updated categories contains category with id: {id}");
    let batch_deleted: Vec<Category> = client.batch_delete(vec![id]).await?;
    info!("Deleted {} categories", batch_deleted.len());
    Ok(())
}
More examples
Hide additional examples
examples/product.rs (line 40)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let start = std::time::Instant::now();
    let products = client.list_all::<Product>().await?;
    info!(
        "Got {} products in {} seconds",
        products.len(),
        start.elapsed().as_secs()
    );
    let random_id = products.first().map(|p| p.id).unwrap_or_default();
    let retrieved = client.retrieve::<Product>(random_id).await?;
    info!("Retrieved product has sku: {}", retrieved.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .visible()
        .build();
    let new_product = Product::builder()
        .name("Test Product For Example")
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let batch_create = vec![new_product.clone()];
    let created: Product = client.create(new_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);
    let update = Product::builder().unfeatured().build();
    let updated: Product = client.update(created.id, update).await?;
    info!(
        "Update product {}, new feature is {}",
        updated.name, updated.featured
    );
    let deleted: Product = client.delete(updated.id).await?;
    info!("Product {} deleted", deleted.name);
    let batch_created: Vec<Product> = client.batch_create(batch_create).await?;
    let id = batch_created.first().ok_or(anyhow!("Error"))?.id;
    let batch_update = Product::builder().id(id).unfeatured().build();
    let _batch_updated: Vec<Product> = client.batch_update(vec![batch_update]).await?;
    let _deleted: Product = client.delete(id).await?;
    Ok(())
}
examples/variation.rs (line 56)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let products = client.list_all::<Product>().await?;
    let random_variable_id = products
        .iter()
        .find(|p| !p.variations.is_empty())
        .map(|p| p.id)
        .unwrap_or_default();
    let variations = client
        .list_all_subentities::<ProductVariation>(random_variable_id)
        .await?;
    info!(
        "Got {} variations for product with id: {random_variable_id}",
        variations.len()
    );
    let retrieved_variation: ProductVariation = client
        .retrieve_subentity(
            random_variable_id,
            variations.first().map(|v| v.id).unwrap_or_default(),
        )
        .await?;
    info!("Retrieved variation has sku: {}", retrieved_variation.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .option("Test")
        .variation()
        .visible()
        .build();
    let new_variable_product = Product::builder()
        .name("Test Product For Example")
        .product_type(ProductType::Variable)
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let created: Product = client.create(new_variable_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);

    let variation = ProductVariation::builder()
        .sku(format!("{} Best", created.sku))
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(96)
        .weight("52")
        .dimensions("5", "4", "3")
        .attribute(None, "Test Attribute", "Best")
        .build();
    let batch_create_variation = vec![variation.clone()];
    let created_variation: ProductVariation =
        client.create_subentity(created.id, variation).await?;
    info!(
        "Variation {} created with price: {}",
        created_variation.sku, created_variation.price
    );
    let update = ProductVariation::builder().regular_price("7000").build();
    let updated_variation: ProductVariation = client
        .update_subentity(created.id, created_variation.id, update)
        .await?;
    info!(
        "Variation {} updated with price: {}",
        updated_variation.sku, updated_variation.price
    );
    let deleted_variation: ProductVariation = client
        .delete_subentity(created.id, updated_variation.id)
        .await?;
    info!("Variation {} deleted", deleted_variation.sku);
    let batch_created_variation: Vec<ProductVariation> = client
        .batch_create_subentity(created.id, batch_create_variation)
        .await?;
    let bcv_id = batch_created_variation
        .first()
        .map(|v| v.id)
        .unwrap_or_default();
    let batch_update_variation = vec![ProductVariation::builder()
        .id(bcv_id)
        .regular_price("777")
        .build()];
    let _batch_updated_variation: Vec<ProductVariation> = client
        .batch_update_subentity(created.id, batch_update_variation)
        .await?;
    let _batch_deleted_variation: Vec<ProductVariation> = client
        .batch_delete_subentity(created.id, vec![bcv_id])
        .await?;
    let deleted: Product = client.delete(created.id).await?;
    info!("Product {} deleted", deleted.name);
    Ok(())
}
Source

pub async fn update<T: Entity>( &self, entity_id: i32, object: impl Serialize, ) -> Result<T>

This API lets you make changes to entity.

§Example
use anyhow::{anyhow, Result};
use rust_woocommerce::{Product, ApiClient, Config};
use tracing::info;

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let update = Product::builder().unfeatured().build();
    let updated: Product = client.update(12345, update).await?;
    info!(
    "Update product {}, new feature is {}",
    updated.name, updated.featured
);
    Ok(())
}
Examples found in repository?
examples/category.rs (line 24)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let categories = client.list_all::<Category>().await?;
    info!("Got {} categories", categories.len());
    let random_id = categories.first().unwrap().id;
    let retrieved: Category = client.retrieve(random_id).await?;
    info!("Retrieved category name: {}", retrieved.name);
    let create = Category::create("Test Category")
        .parent(retrieved.id)
        .description("Test description")
        .display(DisplayOption::Products)
        .image("https://woocommerce.github.io/woocommerce-rest-api-docs/images/logo-95f5c1ab.png");
    let batch_create = create.clone();
    let created: Category = client.create(create).await?;
    info!("Category with id: {} created", created.id);
    let update = Category::update().description("Some description");
    let updated: Category = client.update(created.id, update).await?;
    info!("New description is {}", updated.description);
    let deleted: Category = client.delete(updated.id).await?;
    info!("Category {} deleted", deleted.name);
    let batch_created: Vec<Category> = client.batch_create(vec![batch_create]).await?;
    info!("Batch created {} categories", batch_created.len());
    let batch_update = Category::update()
        .id(batch_created.first().unwrap().id)
        .description("Some description");
    let batch_updated: Vec<Category> = client.batch_update(vec![batch_update]).await?;
    let id = batch_updated.first().unwrap().id;
    info!("Batch updated categories contains category with id: {id}");
    let batch_deleted: Vec<Category> = client.batch_delete(vec![id]).await?;
    info!("Deleted {} categories", batch_deleted.len());
    Ok(())
}
More examples
Hide additional examples
examples/product.rs (line 43)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let start = std::time::Instant::now();
    let products = client.list_all::<Product>().await?;
    info!(
        "Got {} products in {} seconds",
        products.len(),
        start.elapsed().as_secs()
    );
    let random_id = products.first().map(|p| p.id).unwrap_or_default();
    let retrieved = client.retrieve::<Product>(random_id).await?;
    info!("Retrieved product has sku: {}", retrieved.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .visible()
        .build();
    let new_product = Product::builder()
        .name("Test Product For Example")
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let batch_create = vec![new_product.clone()];
    let created: Product = client.create(new_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);
    let update = Product::builder().unfeatured().build();
    let updated: Product = client.update(created.id, update).await?;
    info!(
        "Update product {}, new feature is {}",
        updated.name, updated.featured
    );
    let deleted: Product = client.delete(updated.id).await?;
    info!("Product {} deleted", deleted.name);
    let batch_created: Vec<Product> = client.batch_create(batch_create).await?;
    let id = batch_created.first().ok_or(anyhow!("Error"))?.id;
    let batch_update = Product::builder().id(id).unfeatured().build();
    let _batch_updated: Vec<Product> = client.batch_update(vec![batch_update]).await?;
    let _deleted: Product = client.delete(id).await?;
    Ok(())
}
Source

pub async fn delete<T: Entity>(&self, entity_id: i32) -> Result<T>

This API helps you delete a product.

§Example
use anyhow::Result;
use rust_woocommerce::{Product, ApiClient, Config};
use tracing::info;

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let deleted: Product = client.delete(12345).await?;
    info!("Product {} deleted", deleted.name);
    Ok(())
}
Examples found in repository?
examples/category.rs (line 26)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let categories = client.list_all::<Category>().await?;
    info!("Got {} categories", categories.len());
    let random_id = categories.first().unwrap().id;
    let retrieved: Category = client.retrieve(random_id).await?;
    info!("Retrieved category name: {}", retrieved.name);
    let create = Category::create("Test Category")
        .parent(retrieved.id)
        .description("Test description")
        .display(DisplayOption::Products)
        .image("https://woocommerce.github.io/woocommerce-rest-api-docs/images/logo-95f5c1ab.png");
    let batch_create = create.clone();
    let created: Category = client.create(create).await?;
    info!("Category with id: {} created", created.id);
    let update = Category::update().description("Some description");
    let updated: Category = client.update(created.id, update).await?;
    info!("New description is {}", updated.description);
    let deleted: Category = client.delete(updated.id).await?;
    info!("Category {} deleted", deleted.name);
    let batch_created: Vec<Category> = client.batch_create(vec![batch_create]).await?;
    info!("Batch created {} categories", batch_created.len());
    let batch_update = Category::update()
        .id(batch_created.first().unwrap().id)
        .description("Some description");
    let batch_updated: Vec<Category> = client.batch_update(vec![batch_update]).await?;
    let id = batch_updated.first().unwrap().id;
    info!("Batch updated categories contains category with id: {id}");
    let batch_deleted: Vec<Category> = client.batch_delete(vec![id]).await?;
    info!("Deleted {} categories", batch_deleted.len());
    Ok(())
}
More examples
Hide additional examples
examples/product.rs (line 48)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let start = std::time::Instant::now();
    let products = client.list_all::<Product>().await?;
    info!(
        "Got {} products in {} seconds",
        products.len(),
        start.elapsed().as_secs()
    );
    let random_id = products.first().map(|p| p.id).unwrap_or_default();
    let retrieved = client.retrieve::<Product>(random_id).await?;
    info!("Retrieved product has sku: {}", retrieved.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .visible()
        .build();
    let new_product = Product::builder()
        .name("Test Product For Example")
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let batch_create = vec![new_product.clone()];
    let created: Product = client.create(new_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);
    let update = Product::builder().unfeatured().build();
    let updated: Product = client.update(created.id, update).await?;
    info!(
        "Update product {}, new feature is {}",
        updated.name, updated.featured
    );
    let deleted: Product = client.delete(updated.id).await?;
    info!("Product {} deleted", deleted.name);
    let batch_created: Vec<Product> = client.batch_create(batch_create).await?;
    let id = batch_created.first().ok_or(anyhow!("Error"))?.id;
    let batch_update = Product::builder().id(id).unfeatured().build();
    let _batch_updated: Vec<Product> = client.batch_update(vec![batch_update]).await?;
    let _deleted: Product = client.delete(id).await?;
    Ok(())
}
examples/variation.rs (line 104)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let products = client.list_all::<Product>().await?;
    let random_variable_id = products
        .iter()
        .find(|p| !p.variations.is_empty())
        .map(|p| p.id)
        .unwrap_or_default();
    let variations = client
        .list_all_subentities::<ProductVariation>(random_variable_id)
        .await?;
    info!(
        "Got {} variations for product with id: {random_variable_id}",
        variations.len()
    );
    let retrieved_variation: ProductVariation = client
        .retrieve_subentity(
            random_variable_id,
            variations.first().map(|v| v.id).unwrap_or_default(),
        )
        .await?;
    info!("Retrieved variation has sku: {}", retrieved_variation.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .option("Test")
        .variation()
        .visible()
        .build();
    let new_variable_product = Product::builder()
        .name("Test Product For Example")
        .product_type(ProductType::Variable)
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let created: Product = client.create(new_variable_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);

    let variation = ProductVariation::builder()
        .sku(format!("{} Best", created.sku))
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(96)
        .weight("52")
        .dimensions("5", "4", "3")
        .attribute(None, "Test Attribute", "Best")
        .build();
    let batch_create_variation = vec![variation.clone()];
    let created_variation: ProductVariation =
        client.create_subentity(created.id, variation).await?;
    info!(
        "Variation {} created with price: {}",
        created_variation.sku, created_variation.price
    );
    let update = ProductVariation::builder().regular_price("7000").build();
    let updated_variation: ProductVariation = client
        .update_subentity(created.id, created_variation.id, update)
        .await?;
    info!(
        "Variation {} updated with price: {}",
        updated_variation.sku, updated_variation.price
    );
    let deleted_variation: ProductVariation = client
        .delete_subentity(created.id, updated_variation.id)
        .await?;
    info!("Variation {} deleted", deleted_variation.sku);
    let batch_created_variation: Vec<ProductVariation> = client
        .batch_create_subentity(created.id, batch_create_variation)
        .await?;
    let bcv_id = batch_created_variation
        .first()
        .map(|v| v.id)
        .unwrap_or_default();
    let batch_update_variation = vec![ProductVariation::builder()
        .id(bcv_id)
        .regular_price("777")
        .build()];
    let _batch_updated_variation: Vec<ProductVariation> = client
        .batch_update_subentity(created.id, batch_update_variation)
        .await?;
    let _batch_deleted_variation: Vec<ProductVariation> = client
        .batch_delete_subentity(created.id, vec![bcv_id])
        .await?;
    let deleted: Product = client.delete(created.id).await?;
    info!("Product {} deleted", deleted.name);
    Ok(())
}
Source

pub async fn batch_create<T: Entity, O: Serialize + Clone + Send + 'static>( &self, create_objects: Vec<O>, ) -> Result<Vec<T>>

This API helps you to batch create multiple entities.

§Example
use anyhow::Result;
use rust_woocommerce::{Product, ApiClient, Config, Attribute};
use tracing::info;

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .visible()
        .build();
    let new_product = Product::builder()
        .name("Test Product For Example")
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let batch_create = vec![new_product];
    let batch_created: Vec<Product> = client.batch_create(batch_create).await?;
    Ok(())
}
Examples found in repository?
examples/category.rs (line 28)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let categories = client.list_all::<Category>().await?;
    info!("Got {} categories", categories.len());
    let random_id = categories.first().unwrap().id;
    let retrieved: Category = client.retrieve(random_id).await?;
    info!("Retrieved category name: {}", retrieved.name);
    let create = Category::create("Test Category")
        .parent(retrieved.id)
        .description("Test description")
        .display(DisplayOption::Products)
        .image("https://woocommerce.github.io/woocommerce-rest-api-docs/images/logo-95f5c1ab.png");
    let batch_create = create.clone();
    let created: Category = client.create(create).await?;
    info!("Category with id: {} created", created.id);
    let update = Category::update().description("Some description");
    let updated: Category = client.update(created.id, update).await?;
    info!("New description is {}", updated.description);
    let deleted: Category = client.delete(updated.id).await?;
    info!("Category {} deleted", deleted.name);
    let batch_created: Vec<Category> = client.batch_create(vec![batch_create]).await?;
    info!("Batch created {} categories", batch_created.len());
    let batch_update = Category::update()
        .id(batch_created.first().unwrap().id)
        .description("Some description");
    let batch_updated: Vec<Category> = client.batch_update(vec![batch_update]).await?;
    let id = batch_updated.first().unwrap().id;
    info!("Batch updated categories contains category with id: {id}");
    let batch_deleted: Vec<Category> = client.batch_delete(vec![id]).await?;
    info!("Deleted {} categories", batch_deleted.len());
    Ok(())
}
More examples
Hide additional examples
examples/product.rs (line 50)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let start = std::time::Instant::now();
    let products = client.list_all::<Product>().await?;
    info!(
        "Got {} products in {} seconds",
        products.len(),
        start.elapsed().as_secs()
    );
    let random_id = products.first().map(|p| p.id).unwrap_or_default();
    let retrieved = client.retrieve::<Product>(random_id).await?;
    info!("Retrieved product has sku: {}", retrieved.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .visible()
        .build();
    let new_product = Product::builder()
        .name("Test Product For Example")
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let batch_create = vec![new_product.clone()];
    let created: Product = client.create(new_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);
    let update = Product::builder().unfeatured().build();
    let updated: Product = client.update(created.id, update).await?;
    info!(
        "Update product {}, new feature is {}",
        updated.name, updated.featured
    );
    let deleted: Product = client.delete(updated.id).await?;
    info!("Product {} deleted", deleted.name);
    let batch_created: Vec<Product> = client.batch_create(batch_create).await?;
    let id = batch_created.first().ok_or(anyhow!("Error"))?.id;
    let batch_update = Product::builder().id(id).unfeatured().build();
    let _batch_updated: Vec<Product> = client.batch_update(vec![batch_update]).await?;
    let _deleted: Product = client.delete(id).await?;
    Ok(())
}
Source

pub async fn batch_update<T: Entity, O: Serialize + Clone + Send + 'static>( &self, update_objects: Vec<O>, ) -> Result<Vec<T>>

This API helps you to batch update multiple entities.

§Example
use rust_woocommerce::{ApiClient, Config};
use rust_woocommerce::Category;
use anyhow::Result;
use tracing::info;

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let batch_update = Category::update()
        .id(12345)
        .description("Some description")
        .build();
    let batch_updated: Vec<Category> = client.batch_update(vec![batch_update]).await?;
    Ok(())
}
Examples found in repository?
examples/category.rs (line 33)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let categories = client.list_all::<Category>().await?;
    info!("Got {} categories", categories.len());
    let random_id = categories.first().unwrap().id;
    let retrieved: Category = client.retrieve(random_id).await?;
    info!("Retrieved category name: {}", retrieved.name);
    let create = Category::create("Test Category")
        .parent(retrieved.id)
        .description("Test description")
        .display(DisplayOption::Products)
        .image("https://woocommerce.github.io/woocommerce-rest-api-docs/images/logo-95f5c1ab.png");
    let batch_create = create.clone();
    let created: Category = client.create(create).await?;
    info!("Category with id: {} created", created.id);
    let update = Category::update().description("Some description");
    let updated: Category = client.update(created.id, update).await?;
    info!("New description is {}", updated.description);
    let deleted: Category = client.delete(updated.id).await?;
    info!("Category {} deleted", deleted.name);
    let batch_created: Vec<Category> = client.batch_create(vec![batch_create]).await?;
    info!("Batch created {} categories", batch_created.len());
    let batch_update = Category::update()
        .id(batch_created.first().unwrap().id)
        .description("Some description");
    let batch_updated: Vec<Category> = client.batch_update(vec![batch_update]).await?;
    let id = batch_updated.first().unwrap().id;
    info!("Batch updated categories contains category with id: {id}");
    let batch_deleted: Vec<Category> = client.batch_delete(vec![id]).await?;
    info!("Deleted {} categories", batch_deleted.len());
    Ok(())
}
More examples
Hide additional examples
examples/product.rs (line 53)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let start = std::time::Instant::now();
    let products = client.list_all::<Product>().await?;
    info!(
        "Got {} products in {} seconds",
        products.len(),
        start.elapsed().as_secs()
    );
    let random_id = products.first().map(|p| p.id).unwrap_or_default();
    let retrieved = client.retrieve::<Product>(random_id).await?;
    info!("Retrieved product has sku: {}", retrieved.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .visible()
        .build();
    let new_product = Product::builder()
        .name("Test Product For Example")
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let batch_create = vec![new_product.clone()];
    let created: Product = client.create(new_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);
    let update = Product::builder().unfeatured().build();
    let updated: Product = client.update(created.id, update).await?;
    info!(
        "Update product {}, new feature is {}",
        updated.name, updated.featured
    );
    let deleted: Product = client.delete(updated.id).await?;
    info!("Product {} deleted", deleted.name);
    let batch_created: Vec<Product> = client.batch_create(batch_create).await?;
    let id = batch_created.first().ok_or(anyhow!("Error"))?.id;
    let batch_update = Product::builder().id(id).unfeatured().build();
    let _batch_updated: Vec<Product> = client.batch_update(vec![batch_update]).await?;
    let _deleted: Product = client.delete(id).await?;
    Ok(())
}
Source

pub async fn batch_delete<T: Entity>( &self, delete_objects: Vec<i32>, ) -> Result<Vec<T>>

This API helps you to batch delete multiple entities.

§Example
use rust_woocommerce::{ApiClient, Config};
use rust_woocommerce::Category;
use anyhow::Result;
use tracing::info;

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let batch_deleted: Vec<Category> = client.batch_delete(vec![12345]).await?;
    Ok(())
}
Examples found in repository?
examples/category.rs (line 36)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let categories = client.list_all::<Category>().await?;
    info!("Got {} categories", categories.len());
    let random_id = categories.first().unwrap().id;
    let retrieved: Category = client.retrieve(random_id).await?;
    info!("Retrieved category name: {}", retrieved.name);
    let create = Category::create("Test Category")
        .parent(retrieved.id)
        .description("Test description")
        .display(DisplayOption::Products)
        .image("https://woocommerce.github.io/woocommerce-rest-api-docs/images/logo-95f5c1ab.png");
    let batch_create = create.clone();
    let created: Category = client.create(create).await?;
    info!("Category with id: {} created", created.id);
    let update = Category::update().description("Some description");
    let updated: Category = client.update(created.id, update).await?;
    info!("New description is {}", updated.description);
    let deleted: Category = client.delete(updated.id).await?;
    info!("Category {} deleted", deleted.name);
    let batch_created: Vec<Category> = client.batch_create(vec![batch_create]).await?;
    info!("Batch created {} categories", batch_created.len());
    let batch_update = Category::update()
        .id(batch_created.first().unwrap().id)
        .description("Some description");
    let batch_updated: Vec<Category> = client.batch_update(vec![batch_update]).await?;
    let id = batch_updated.first().unwrap().id;
    info!("Batch updated categories contains category with id: {id}");
    let batch_deleted: Vec<Category> = client.batch_delete(vec![id]).await?;
    info!("Deleted {} categories", batch_deleted.len());
    Ok(())
}
Source

pub async fn retrieve_subentity<T: Entity>( &self, entity_id: i32, subentity_id: i32, ) -> Result<T>

This API lets you retrieve and view a specific subentity by ID.

§Example
use anyhow::Result;
use tracing::info;

use rust_woocommerce::{ApiClient, Config, ProductVariation};

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let retrieved_variation: ProductVariation = client
        .retrieve_subentity(12345, 42)
        .await?;
    info!("Retrieved variation has sku: {}", retrieved_variation.sku);
    Ok(())
}
Examples found in repository?
examples/variation.rs (lines 28-31)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let products = client.list_all::<Product>().await?;
    let random_variable_id = products
        .iter()
        .find(|p| !p.variations.is_empty())
        .map(|p| p.id)
        .unwrap_or_default();
    let variations = client
        .list_all_subentities::<ProductVariation>(random_variable_id)
        .await?;
    info!(
        "Got {} variations for product with id: {random_variable_id}",
        variations.len()
    );
    let retrieved_variation: ProductVariation = client
        .retrieve_subentity(
            random_variable_id,
            variations.first().map(|v| v.id).unwrap_or_default(),
        )
        .await?;
    info!("Retrieved variation has sku: {}", retrieved_variation.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .option("Test")
        .variation()
        .visible()
        .build();
    let new_variable_product = Product::builder()
        .name("Test Product For Example")
        .product_type(ProductType::Variable)
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let created: Product = client.create(new_variable_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);

    let variation = ProductVariation::builder()
        .sku(format!("{} Best", created.sku))
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(96)
        .weight("52")
        .dimensions("5", "4", "3")
        .attribute(None, "Test Attribute", "Best")
        .build();
    let batch_create_variation = vec![variation.clone()];
    let created_variation: ProductVariation =
        client.create_subentity(created.id, variation).await?;
    info!(
        "Variation {} created with price: {}",
        created_variation.sku, created_variation.price
    );
    let update = ProductVariation::builder().regular_price("7000").build();
    let updated_variation: ProductVariation = client
        .update_subentity(created.id, created_variation.id, update)
        .await?;
    info!(
        "Variation {} updated with price: {}",
        updated_variation.sku, updated_variation.price
    );
    let deleted_variation: ProductVariation = client
        .delete_subentity(created.id, updated_variation.id)
        .await?;
    info!("Variation {} deleted", deleted_variation.sku);
    let batch_created_variation: Vec<ProductVariation> = client
        .batch_create_subentity(created.id, batch_create_variation)
        .await?;
    let bcv_id = batch_created_variation
        .first()
        .map(|v| v.id)
        .unwrap_or_default();
    let batch_update_variation = vec![ProductVariation::builder()
        .id(bcv_id)
        .regular_price("777")
        .build()];
    let _batch_updated_variation: Vec<ProductVariation> = client
        .batch_update_subentity(created.id, batch_update_variation)
        .await?;
    let _batch_deleted_variation: Vec<ProductVariation> = client
        .batch_delete_subentity(created.id, vec![bcv_id])
        .await?;
    let deleted: Product = client.delete(created.id).await?;
    info!("Product {} deleted", deleted.name);
    Ok(())
}
Source

pub async fn list_all_subentities<T: Entity>( &self, entity_id: i32, ) -> Result<Vec<T>>

This API lets you view all subentities of entity.

§Example
use anyhow::Result;
use tracing::info;

use rust_woocommerce::{ApiClient, Config, ProductVariation};

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let variations = client
        .list_all_subentities::<ProductVariation>(12345)
        .await?;
    info!(
        "Got {} variations for product with id: 12345",
        variations.len()
    );
    Ok(())
}
Examples found in repository?
examples/variation.rs (line 21)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let products = client.list_all::<Product>().await?;
    let random_variable_id = products
        .iter()
        .find(|p| !p.variations.is_empty())
        .map(|p| p.id)
        .unwrap_or_default();
    let variations = client
        .list_all_subentities::<ProductVariation>(random_variable_id)
        .await?;
    info!(
        "Got {} variations for product with id: {random_variable_id}",
        variations.len()
    );
    let retrieved_variation: ProductVariation = client
        .retrieve_subentity(
            random_variable_id,
            variations.first().map(|v| v.id).unwrap_or_default(),
        )
        .await?;
    info!("Retrieved variation has sku: {}", retrieved_variation.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .option("Test")
        .variation()
        .visible()
        .build();
    let new_variable_product = Product::builder()
        .name("Test Product For Example")
        .product_type(ProductType::Variable)
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let created: Product = client.create(new_variable_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);

    let variation = ProductVariation::builder()
        .sku(format!("{} Best", created.sku))
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(96)
        .weight("52")
        .dimensions("5", "4", "3")
        .attribute(None, "Test Attribute", "Best")
        .build();
    let batch_create_variation = vec![variation.clone()];
    let created_variation: ProductVariation =
        client.create_subentity(created.id, variation).await?;
    info!(
        "Variation {} created with price: {}",
        created_variation.sku, created_variation.price
    );
    let update = ProductVariation::builder().regular_price("7000").build();
    let updated_variation: ProductVariation = client
        .update_subentity(created.id, created_variation.id, update)
        .await?;
    info!(
        "Variation {} updated with price: {}",
        updated_variation.sku, updated_variation.price
    );
    let deleted_variation: ProductVariation = client
        .delete_subentity(created.id, updated_variation.id)
        .await?;
    info!("Variation {} deleted", deleted_variation.sku);
    let batch_created_variation: Vec<ProductVariation> = client
        .batch_create_subentity(created.id, batch_create_variation)
        .await?;
    let bcv_id = batch_created_variation
        .first()
        .map(|v| v.id)
        .unwrap_or_default();
    let batch_update_variation = vec![ProductVariation::builder()
        .id(bcv_id)
        .regular_price("777")
        .build()];
    let _batch_updated_variation: Vec<ProductVariation> = client
        .batch_update_subentity(created.id, batch_update_variation)
        .await?;
    let _batch_deleted_variation: Vec<ProductVariation> = client
        .batch_delete_subentity(created.id, vec![bcv_id])
        .await?;
    let deleted: Product = client.delete(created.id).await?;
    info!("Product {} deleted", deleted.name);
    Ok(())
}
Source

pub async fn create_subentity<T: Entity>( &self, entity_id: i32, object: impl Serialize, ) -> Result<T>

This API helps you create a new subentity.

§Example
use anyhow::Result;
use tracing::info;

use rust_woocommerce::{ApiClient, Config, ProductVariation};

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let variation = ProductVariation::builder()
        .sku("Best variation")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(96)
        .weight("52")
        .dimensions("5", "4", "3")
        .attribute(None, "Test Attribute", "Best")
        .build();
    let created_variation: ProductVariation =
        client.create_subentity(12345, variation).await?;
    info!(
        "Variation {} created with price: {}",
        created_variation.sku, created_variation.price
    );
    Ok(())
}
Examples found in repository?
examples/variation.rs (line 70)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let products = client.list_all::<Product>().await?;
    let random_variable_id = products
        .iter()
        .find(|p| !p.variations.is_empty())
        .map(|p| p.id)
        .unwrap_or_default();
    let variations = client
        .list_all_subentities::<ProductVariation>(random_variable_id)
        .await?;
    info!(
        "Got {} variations for product with id: {random_variable_id}",
        variations.len()
    );
    let retrieved_variation: ProductVariation = client
        .retrieve_subentity(
            random_variable_id,
            variations.first().map(|v| v.id).unwrap_or_default(),
        )
        .await?;
    info!("Retrieved variation has sku: {}", retrieved_variation.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .option("Test")
        .variation()
        .visible()
        .build();
    let new_variable_product = Product::builder()
        .name("Test Product For Example")
        .product_type(ProductType::Variable)
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let created: Product = client.create(new_variable_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);

    let variation = ProductVariation::builder()
        .sku(format!("{} Best", created.sku))
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(96)
        .weight("52")
        .dimensions("5", "4", "3")
        .attribute(None, "Test Attribute", "Best")
        .build();
    let batch_create_variation = vec![variation.clone()];
    let created_variation: ProductVariation =
        client.create_subentity(created.id, variation).await?;
    info!(
        "Variation {} created with price: {}",
        created_variation.sku, created_variation.price
    );
    let update = ProductVariation::builder().regular_price("7000").build();
    let updated_variation: ProductVariation = client
        .update_subentity(created.id, created_variation.id, update)
        .await?;
    info!(
        "Variation {} updated with price: {}",
        updated_variation.sku, updated_variation.price
    );
    let deleted_variation: ProductVariation = client
        .delete_subentity(created.id, updated_variation.id)
        .await?;
    info!("Variation {} deleted", deleted_variation.sku);
    let batch_created_variation: Vec<ProductVariation> = client
        .batch_create_subentity(created.id, batch_create_variation)
        .await?;
    let bcv_id = batch_created_variation
        .first()
        .map(|v| v.id)
        .unwrap_or_default();
    let batch_update_variation = vec![ProductVariation::builder()
        .id(bcv_id)
        .regular_price("777")
        .build()];
    let _batch_updated_variation: Vec<ProductVariation> = client
        .batch_update_subentity(created.id, batch_update_variation)
        .await?;
    let _batch_deleted_variation: Vec<ProductVariation> = client
        .batch_delete_subentity(created.id, vec![bcv_id])
        .await?;
    let deleted: Product = client.delete(created.id).await?;
    info!("Product {} deleted", deleted.name);
    Ok(())
}
Source

pub async fn update_subentity<T: Entity>( &self, entity_id: i32, subentity_id: i32, object: impl Serialize, ) -> Result<T>

This API lets you make changes to subentity.

§Example
use anyhow::Result;
use tracing::info;

use rust_woocommerce::{ApiClient, Config, ProductVariation};

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let update = ProductVariation::builder().regular_price("7000").build();
    let updated_variation: ProductVariation = client
        .update_subentity(12345, 42, update)
        .await?;
    info!(
        "Variation {} updated with price: {}",
        updated_variation.sku, updated_variation.price
    );
    Ok(())
}
Examples found in repository?
examples/variation.rs (line 77)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let products = client.list_all::<Product>().await?;
    let random_variable_id = products
        .iter()
        .find(|p| !p.variations.is_empty())
        .map(|p| p.id)
        .unwrap_or_default();
    let variations = client
        .list_all_subentities::<ProductVariation>(random_variable_id)
        .await?;
    info!(
        "Got {} variations for product with id: {random_variable_id}",
        variations.len()
    );
    let retrieved_variation: ProductVariation = client
        .retrieve_subentity(
            random_variable_id,
            variations.first().map(|v| v.id).unwrap_or_default(),
        )
        .await?;
    info!("Retrieved variation has sku: {}", retrieved_variation.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .option("Test")
        .variation()
        .visible()
        .build();
    let new_variable_product = Product::builder()
        .name("Test Product For Example")
        .product_type(ProductType::Variable)
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let created: Product = client.create(new_variable_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);

    let variation = ProductVariation::builder()
        .sku(format!("{} Best", created.sku))
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(96)
        .weight("52")
        .dimensions("5", "4", "3")
        .attribute(None, "Test Attribute", "Best")
        .build();
    let batch_create_variation = vec![variation.clone()];
    let created_variation: ProductVariation =
        client.create_subentity(created.id, variation).await?;
    info!(
        "Variation {} created with price: {}",
        created_variation.sku, created_variation.price
    );
    let update = ProductVariation::builder().regular_price("7000").build();
    let updated_variation: ProductVariation = client
        .update_subentity(created.id, created_variation.id, update)
        .await?;
    info!(
        "Variation {} updated with price: {}",
        updated_variation.sku, updated_variation.price
    );
    let deleted_variation: ProductVariation = client
        .delete_subentity(created.id, updated_variation.id)
        .await?;
    info!("Variation {} deleted", deleted_variation.sku);
    let batch_created_variation: Vec<ProductVariation> = client
        .batch_create_subentity(created.id, batch_create_variation)
        .await?;
    let bcv_id = batch_created_variation
        .first()
        .map(|v| v.id)
        .unwrap_or_default();
    let batch_update_variation = vec![ProductVariation::builder()
        .id(bcv_id)
        .regular_price("777")
        .build()];
    let _batch_updated_variation: Vec<ProductVariation> = client
        .batch_update_subentity(created.id, batch_update_variation)
        .await?;
    let _batch_deleted_variation: Vec<ProductVariation> = client
        .batch_delete_subentity(created.id, vec![bcv_id])
        .await?;
    let deleted: Product = client.delete(created.id).await?;
    info!("Product {} deleted", deleted.name);
    Ok(())
}
Source

pub async fn delete_subentity<T: Entity>( &self, entity_id: i32, subentity_id: i32, ) -> Result<T>

This API helps you delete subentity.

§Example
use anyhow::Result;
use tracing::info;

use rust_woocommerce::{ApiClient, Config, ProductVariation};

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let deleted_variation: ProductVariation = client
        .delete_subentity(12345, 42)
        .await?;
    info!("Variation {} deleted", deleted_variation.sku);
    Ok(())
}
Examples found in repository?
examples/variation.rs (line 84)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let products = client.list_all::<Product>().await?;
    let random_variable_id = products
        .iter()
        .find(|p| !p.variations.is_empty())
        .map(|p| p.id)
        .unwrap_or_default();
    let variations = client
        .list_all_subentities::<ProductVariation>(random_variable_id)
        .await?;
    info!(
        "Got {} variations for product with id: {random_variable_id}",
        variations.len()
    );
    let retrieved_variation: ProductVariation = client
        .retrieve_subentity(
            random_variable_id,
            variations.first().map(|v| v.id).unwrap_or_default(),
        )
        .await?;
    info!("Retrieved variation has sku: {}", retrieved_variation.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .option("Test")
        .variation()
        .visible()
        .build();
    let new_variable_product = Product::builder()
        .name("Test Product For Example")
        .product_type(ProductType::Variable)
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let created: Product = client.create(new_variable_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);

    let variation = ProductVariation::builder()
        .sku(format!("{} Best", created.sku))
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(96)
        .weight("52")
        .dimensions("5", "4", "3")
        .attribute(None, "Test Attribute", "Best")
        .build();
    let batch_create_variation = vec![variation.clone()];
    let created_variation: ProductVariation =
        client.create_subentity(created.id, variation).await?;
    info!(
        "Variation {} created with price: {}",
        created_variation.sku, created_variation.price
    );
    let update = ProductVariation::builder().regular_price("7000").build();
    let updated_variation: ProductVariation = client
        .update_subentity(created.id, created_variation.id, update)
        .await?;
    info!(
        "Variation {} updated with price: {}",
        updated_variation.sku, updated_variation.price
    );
    let deleted_variation: ProductVariation = client
        .delete_subentity(created.id, updated_variation.id)
        .await?;
    info!("Variation {} deleted", deleted_variation.sku);
    let batch_created_variation: Vec<ProductVariation> = client
        .batch_create_subentity(created.id, batch_create_variation)
        .await?;
    let bcv_id = batch_created_variation
        .first()
        .map(|v| v.id)
        .unwrap_or_default();
    let batch_update_variation = vec![ProductVariation::builder()
        .id(bcv_id)
        .regular_price("777")
        .build()];
    let _batch_updated_variation: Vec<ProductVariation> = client
        .batch_update_subentity(created.id, batch_update_variation)
        .await?;
    let _batch_deleted_variation: Vec<ProductVariation> = client
        .batch_delete_subentity(created.id, vec![bcv_id])
        .await?;
    let deleted: Product = client.delete(created.id).await?;
    info!("Product {} deleted", deleted.name);
    Ok(())
}
Source

pub async fn batch_create_subentity<T: Entity, O: Serialize + Clone + Send + 'static>( &self, entity_id: i32, create_objects: Vec<O>, ) -> Result<Vec<T>>

This API helps you to batch create subentities.

§Example
use anyhow::Result;
use tracing::info;

use rust_woocommerce::{ApiClient, Config, ProductVariation};

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let variation = ProductVariation::builder()
        .sku("Best SKU")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(96)
        .weight("52")
        .dimensions("5", "4", "3")
        .attribute(None, "Test Attribute", "Best")
        .build();
    let batch_created_variation: Vec<ProductVariation> = client
        .batch_create_subentity(12345, vec![variation])
        .await?;
    Ok(())
}
Examples found in repository?
examples/variation.rs (line 88)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let products = client.list_all::<Product>().await?;
    let random_variable_id = products
        .iter()
        .find(|p| !p.variations.is_empty())
        .map(|p| p.id)
        .unwrap_or_default();
    let variations = client
        .list_all_subentities::<ProductVariation>(random_variable_id)
        .await?;
    info!(
        "Got {} variations for product with id: {random_variable_id}",
        variations.len()
    );
    let retrieved_variation: ProductVariation = client
        .retrieve_subentity(
            random_variable_id,
            variations.first().map(|v| v.id).unwrap_or_default(),
        )
        .await?;
    info!("Retrieved variation has sku: {}", retrieved_variation.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .option("Test")
        .variation()
        .visible()
        .build();
    let new_variable_product = Product::builder()
        .name("Test Product For Example")
        .product_type(ProductType::Variable)
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let created: Product = client.create(new_variable_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);

    let variation = ProductVariation::builder()
        .sku(format!("{} Best", created.sku))
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(96)
        .weight("52")
        .dimensions("5", "4", "3")
        .attribute(None, "Test Attribute", "Best")
        .build();
    let batch_create_variation = vec![variation.clone()];
    let created_variation: ProductVariation =
        client.create_subentity(created.id, variation).await?;
    info!(
        "Variation {} created with price: {}",
        created_variation.sku, created_variation.price
    );
    let update = ProductVariation::builder().regular_price("7000").build();
    let updated_variation: ProductVariation = client
        .update_subentity(created.id, created_variation.id, update)
        .await?;
    info!(
        "Variation {} updated with price: {}",
        updated_variation.sku, updated_variation.price
    );
    let deleted_variation: ProductVariation = client
        .delete_subentity(created.id, updated_variation.id)
        .await?;
    info!("Variation {} deleted", deleted_variation.sku);
    let batch_created_variation: Vec<ProductVariation> = client
        .batch_create_subentity(created.id, batch_create_variation)
        .await?;
    let bcv_id = batch_created_variation
        .first()
        .map(|v| v.id)
        .unwrap_or_default();
    let batch_update_variation = vec![ProductVariation::builder()
        .id(bcv_id)
        .regular_price("777")
        .build()];
    let _batch_updated_variation: Vec<ProductVariation> = client
        .batch_update_subentity(created.id, batch_update_variation)
        .await?;
    let _batch_deleted_variation: Vec<ProductVariation> = client
        .batch_delete_subentity(created.id, vec![bcv_id])
        .await?;
    let deleted: Product = client.delete(created.id).await?;
    info!("Product {} deleted", deleted.name);
    Ok(())
}
Source

pub async fn batch_update_subentity<T: Entity, O: Serialize + Clone + Send + 'static>( &self, entity_id: i32, update_objects: Vec<O>, ) -> Result<Vec<T>>

This API helps you to batch update subentities.

§Example
use anyhow::Result;
use tracing::info;

use rust_woocommerce::{ApiClient, Config, ProductVariation};

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let batch_update_variation = vec![ProductVariation::builder()
        .id(42)
        .regular_price("777")
        .build()];
    let batch_updated_variation: Vec<ProductVariation> = client
        .batch_update_subentity(12345, batch_update_variation)
        .await?;
    Ok(())
}
Examples found in repository?
examples/variation.rs (line 99)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let products = client.list_all::<Product>().await?;
    let random_variable_id = products
        .iter()
        .find(|p| !p.variations.is_empty())
        .map(|p| p.id)
        .unwrap_or_default();
    let variations = client
        .list_all_subentities::<ProductVariation>(random_variable_id)
        .await?;
    info!(
        "Got {} variations for product with id: {random_variable_id}",
        variations.len()
    );
    let retrieved_variation: ProductVariation = client
        .retrieve_subentity(
            random_variable_id,
            variations.first().map(|v| v.id).unwrap_or_default(),
        )
        .await?;
    info!("Retrieved variation has sku: {}", retrieved_variation.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .option("Test")
        .variation()
        .visible()
        .build();
    let new_variable_product = Product::builder()
        .name("Test Product For Example")
        .product_type(ProductType::Variable)
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let created: Product = client.create(new_variable_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);

    let variation = ProductVariation::builder()
        .sku(format!("{} Best", created.sku))
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(96)
        .weight("52")
        .dimensions("5", "4", "3")
        .attribute(None, "Test Attribute", "Best")
        .build();
    let batch_create_variation = vec![variation.clone()];
    let created_variation: ProductVariation =
        client.create_subentity(created.id, variation).await?;
    info!(
        "Variation {} created with price: {}",
        created_variation.sku, created_variation.price
    );
    let update = ProductVariation::builder().regular_price("7000").build();
    let updated_variation: ProductVariation = client
        .update_subentity(created.id, created_variation.id, update)
        .await?;
    info!(
        "Variation {} updated with price: {}",
        updated_variation.sku, updated_variation.price
    );
    let deleted_variation: ProductVariation = client
        .delete_subentity(created.id, updated_variation.id)
        .await?;
    info!("Variation {} deleted", deleted_variation.sku);
    let batch_created_variation: Vec<ProductVariation> = client
        .batch_create_subentity(created.id, batch_create_variation)
        .await?;
    let bcv_id = batch_created_variation
        .first()
        .map(|v| v.id)
        .unwrap_or_default();
    let batch_update_variation = vec![ProductVariation::builder()
        .id(bcv_id)
        .regular_price("777")
        .build()];
    let _batch_updated_variation: Vec<ProductVariation> = client
        .batch_update_subentity(created.id, batch_update_variation)
        .await?;
    let _batch_deleted_variation: Vec<ProductVariation> = client
        .batch_delete_subentity(created.id, vec![bcv_id])
        .await?;
    let deleted: Product = client.delete(created.id).await?;
    info!("Product {} deleted", deleted.name);
    Ok(())
}
Source

pub async fn batch_delete_subentity<T: Entity, O: Serialize + Clone + Send + 'static>( &self, entity_id: i32, delete_objects: Vec<O>, ) -> Result<Vec<T>>

This API helps you to batch delete subentities.

§Example
use anyhow::Result;
use tracing::info;

use rust_woocommerce::{ApiClient, Config, ProductVariation};

#[tokio::main]
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let batch_deleted_variation: Vec<ProductVariation> = client
        .batch_delete_subentity(12345, vec![42])
        .await?;
    Ok(())
}
Examples found in repository?
examples/variation.rs (line 102)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let products = client.list_all::<Product>().await?;
    let random_variable_id = products
        .iter()
        .find(|p| !p.variations.is_empty())
        .map(|p| p.id)
        .unwrap_or_default();
    let variations = client
        .list_all_subentities::<ProductVariation>(random_variable_id)
        .await?;
    info!(
        "Got {} variations for product with id: {random_variable_id}",
        variations.len()
    );
    let retrieved_variation: ProductVariation = client
        .retrieve_subentity(
            random_variable_id,
            variations.first().map(|v| v.id).unwrap_or_default(),
        )
        .await?;
    info!("Retrieved variation has sku: {}", retrieved_variation.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .option("Test")
        .variation()
        .visible()
        .build();
    let new_variable_product = Product::builder()
        .name("Test Product For Example")
        .product_type(ProductType::Variable)
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let created: Product = client.create(new_variable_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);

    let variation = ProductVariation::builder()
        .sku(format!("{} Best", created.sku))
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(96)
        .weight("52")
        .dimensions("5", "4", "3")
        .attribute(None, "Test Attribute", "Best")
        .build();
    let batch_create_variation = vec![variation.clone()];
    let created_variation: ProductVariation =
        client.create_subentity(created.id, variation).await?;
    info!(
        "Variation {} created with price: {}",
        created_variation.sku, created_variation.price
    );
    let update = ProductVariation::builder().regular_price("7000").build();
    let updated_variation: ProductVariation = client
        .update_subentity(created.id, created_variation.id, update)
        .await?;
    info!(
        "Variation {} updated with price: {}",
        updated_variation.sku, updated_variation.price
    );
    let deleted_variation: ProductVariation = client
        .delete_subentity(created.id, updated_variation.id)
        .await?;
    info!("Variation {} deleted", deleted_variation.sku);
    let batch_created_variation: Vec<ProductVariation> = client
        .batch_create_subentity(created.id, batch_create_variation)
        .await?;
    let bcv_id = batch_created_variation
        .first()
        .map(|v| v.id)
        .unwrap_or_default();
    let batch_update_variation = vec![ProductVariation::builder()
        .id(bcv_id)
        .regular_price("777")
        .build()];
    let _batch_updated_variation: Vec<ProductVariation> = client
        .batch_update_subentity(created.id, batch_update_variation)
        .await?;
    let _batch_deleted_variation: Vec<ProductVariation> = client
        .batch_delete_subentity(created.id, vec![bcv_id])
        .await?;
    let deleted: Product = client.delete(created.id).await?;
    info!("Product {} deleted", deleted.name);
    Ok(())
}
Source§

impl ApiClient

Source

pub fn new(config: &Config) -> Result<Self>

Create a new ApiClient instance using configuration

§Arguments
  • config - A reference to a Config instance containing necessary parameters
§Returns

A Result containing the ApiClient instance if successful, or an error

Examples found in repository?
examples/data.rs (line 8)
5
6
7
8
9
10
11
12
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let data = client.list_all::<Data>().await?;
    info!("Got {} data", data.len());
    Ok(())
}
More examples
Hide additional examples
examples/customer.rs (line 9)
6
7
8
9
10
11
12
13
14
15
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let customers = client.list_all::<Customer>().await?;
    info!("Got {} customers", customers.len());
    let retrieved: Customer = client.retrieve(customers.first().unwrap().id).await?;
    info!("Retrieved customer name is {}", retrieved.first_name);
    Ok(())
}
examples/order.rs (line 10)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let orders = client.list_all::<Order>().await?;
    info!("Got {} orders", orders.len());
    let random_order_id = orders.first().ok_or(anyhow!("Error"))?.id;
    let retrieved_order = client.retrieve::<Order>(random_order_id).await?;
    info!(
        "Got order with number: {} with total: {}",
        retrieved_order.number, retrieved_order.total
    );
    Ok(())
}
examples/category.rs (line 9)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
async fn main() -> anyhow::Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let categories = client.list_all::<Category>().await?;
    info!("Got {} categories", categories.len());
    let random_id = categories.first().unwrap().id;
    let retrieved: Category = client.retrieve(random_id).await?;
    info!("Retrieved category name: {}", retrieved.name);
    let create = Category::create("Test Category")
        .parent(retrieved.id)
        .description("Test description")
        .display(DisplayOption::Products)
        .image("https://woocommerce.github.io/woocommerce-rest-api-docs/images/logo-95f5c1ab.png");
    let batch_create = create.clone();
    let created: Category = client.create(create).await?;
    info!("Category with id: {} created", created.id);
    let update = Category::update().description("Some description");
    let updated: Category = client.update(created.id, update).await?;
    info!("New description is {}", updated.description);
    let deleted: Category = client.delete(updated.id).await?;
    info!("Category {} deleted", deleted.name);
    let batch_created: Vec<Category> = client.batch_create(vec![batch_create]).await?;
    info!("Batch created {} categories", batch_created.len());
    let batch_update = Category::update()
        .id(batch_created.first().unwrap().id)
        .description("Some description");
    let batch_updated: Vec<Category> = client.batch_update(vec![batch_update]).await?;
    let id = batch_updated.first().unwrap().id;
    info!("Batch updated categories contains category with id: {id}");
    let batch_deleted: Vec<Category> = client.batch_delete(vec![id]).await?;
    info!("Deleted {} categories", batch_deleted.len());
    Ok(())
}
examples/product.rs (line 9)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let start = std::time::Instant::now();
    let products = client.list_all::<Product>().await?;
    info!(
        "Got {} products in {} seconds",
        products.len(),
        start.elapsed().as_secs()
    );
    let random_id = products.first().map(|p| p.id).unwrap_or_default();
    let retrieved = client.retrieve::<Product>(random_id).await?;
    info!("Retrieved product has sku: {}", retrieved.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .visible()
        .build();
    let new_product = Product::builder()
        .name("Test Product For Example")
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let batch_create = vec![new_product.clone()];
    let created: Product = client.create(new_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);
    let update = Product::builder().unfeatured().build();
    let updated: Product = client.update(created.id, update).await?;
    info!(
        "Update product {}, new feature is {}",
        updated.name, updated.featured
    );
    let deleted: Product = client.delete(updated.id).await?;
    info!("Product {} deleted", deleted.name);
    let batch_created: Vec<Product> = client.batch_create(batch_create).await?;
    let id = batch_created.first().ok_or(anyhow!("Error"))?.id;
    let batch_update = Product::builder().id(id).unfeatured().build();
    let _batch_updated: Vec<Product> = client.batch_update(vec![batch_update]).await?;
    let _deleted: Product = client.delete(id).await?;
    Ok(())
}
examples/variation.rs (line 13)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
async fn main() -> Result<()> {
    tracing_subscriber::fmt::init();
    let config = Config::new("woo.toml")?;
    let client = ApiClient::new(&config)?;
    let products = client.list_all::<Product>().await?;
    let random_variable_id = products
        .iter()
        .find(|p| !p.variations.is_empty())
        .map(|p| p.id)
        .unwrap_or_default();
    let variations = client
        .list_all_subentities::<ProductVariation>(random_variable_id)
        .await?;
    info!(
        "Got {} variations for product with id: {random_variable_id}",
        variations.len()
    );
    let retrieved_variation: ProductVariation = client
        .retrieve_subentity(
            random_variable_id,
            variations.first().map(|v| v.id).unwrap_or_default(),
        )
        .await?;
    info!("Retrieved variation has sku: {}", retrieved_variation.sku);
    let attribute = Attribute::builder()
        .name("Test Attribute")
        .option("Best")
        .option("Test")
        .variation()
        .visible()
        .build();
    let new_variable_product = Product::builder()
        .name("Test Product For Example")
        .product_type(ProductType::Variable)
        .featured()
        .short_description("The most professional description")
        .sku("product for test 42")
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(42)
        .weight("50")
        .dimensions("4", "3", "2")
        .shipping_class("large")
        .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
        .attribute(attribute)
        .build();
    let created: Product = client.create(new_variable_product).await?;
    info!("Create product {} with id: {}", created.name, created.id);

    let variation = ProductVariation::builder()
        .sku(format!("{} Best", created.sku))
        .regular_price("6969")
        .manage_stock()
        .stock_quantity(96)
        .weight("52")
        .dimensions("5", "4", "3")
        .attribute(None, "Test Attribute", "Best")
        .build();
    let batch_create_variation = vec![variation.clone()];
    let created_variation: ProductVariation =
        client.create_subentity(created.id, variation).await?;
    info!(
        "Variation {} created with price: {}",
        created_variation.sku, created_variation.price
    );
    let update = ProductVariation::builder().regular_price("7000").build();
    let updated_variation: ProductVariation = client
        .update_subentity(created.id, created_variation.id, update)
        .await?;
    info!(
        "Variation {} updated with price: {}",
        updated_variation.sku, updated_variation.price
    );
    let deleted_variation: ProductVariation = client
        .delete_subentity(created.id, updated_variation.id)
        .await?;
    info!("Variation {} deleted", deleted_variation.sku);
    let batch_created_variation: Vec<ProductVariation> = client
        .batch_create_subentity(created.id, batch_create_variation)
        .await?;
    let bcv_id = batch_created_variation
        .first()
        .map(|v| v.id)
        .unwrap_or_default();
    let batch_update_variation = vec![ProductVariation::builder()
        .id(bcv_id)
        .regular_price("777")
        .build()];
    let _batch_updated_variation: Vec<ProductVariation> = client
        .batch_update_subentity(created.id, batch_update_variation)
        .await?;
    let _batch_deleted_variation: Vec<ProductVariation> = client
        .batch_delete_subentity(created.id, vec![bcv_id])
        .await?;
    let deleted: Product = client.delete(created.id).await?;
    info!("Product {} deleted", deleted.name);
    Ok(())
}
Source

pub fn from_env() -> Result<Self>

Create a new ApiClient instance using environment variables

§Returns

A Result containing the ApiClient instance if successful, or an error

Source

pub fn ck(&self) -> String

Get the Consumer Key

Source

pub fn cs(&self) -> String

Get the Consumer Secret

Source

pub fn client(&self) -> Client

Get the reqwest Client

Source

pub fn base_url(&self) -> String

Get the base URL as a string

Trait Implementations§

Source§

impl Clone for ApiClient

Source§

fn clone(&self) -> ApiClient

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more