From 5017104e63f72fced16b4547ffd6885a535997f6 Mon Sep 17 00:00:00 2001 From: Paul Woolcock Date: Fri, 24 Aug 2018 10:44:00 -0400 Subject: [PATCH] Make the examples no-ops when `toml` is not enabled --- examples/follow_profile.rs | 8 ++++++++ examples/print_your_profile.rs | 8 ++++++++ examples/register.rs | 13 ++++++++++++- examples/search.rs | 8 ++++++++ examples/upload_photo.rs | 8 ++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) diff --git a/examples/follow_profile.rs b/examples/follow_profile.rs index 01f6ed2..f6fb468 100644 --- a/examples/follow_profile.rs +++ b/examples/follow_profile.rs @@ -1,8 +1,11 @@ +#![cfg_attr(not(feature = "toml"), allow(dead_code))] +#![cfg_attr(not(feature = "toml"), allow(unused_imports))] mod register; use register::MastodonClient; use std::error; +#[cfg(feature = "toml")] fn main() -> Result<(), Box> { let mastodon = register::get_mastodon_data()?; let input = register::read_line("Enter the account id you'd like to follow: ")?; @@ -12,3 +15,8 @@ fn main() -> Result<(), Box> { Ok(()) } + +#[cfg(not(feature = "toml"))] +fn main() { + println!("examples require the `toml` feature, run this command for this example:\n\ncargo run --example follow_profile --features toml\n"); +} diff --git a/examples/print_your_profile.rs b/examples/print_your_profile.rs index 47a15ec..4608233 100644 --- a/examples/print_your_profile.rs +++ b/examples/print_your_profile.rs @@ -1,8 +1,11 @@ +#![cfg_attr(not(feature = "toml"), allow(dead_code))] +#![cfg_attr(not(feature = "toml"), allow(unused_imports))] mod register; use register::MastodonClient; use std::error; +#[cfg(feature = "toml")] fn main() -> Result<(), Box> { let mastodon = register::get_mastodon_data()?; let you = mastodon.verify_credentials()?; @@ -11,3 +14,8 @@ fn main() -> Result<(), Box> { Ok(()) } + +#[cfg(not(feature = "toml"))] +fn main() { + println!("examples require the `toml` feature, run this command for this example:\n\ncargo run --example print_your_profile --features toml\n"); +} diff --git a/examples/register.rs b/examples/register.rs index c429e07..cfa846d 100644 --- a/examples/register.rs +++ b/examples/register.rs @@ -1,3 +1,5 @@ +#![cfg_attr(not(feature = "toml"), allow(dead_code))] +#![cfg_attr(not(feature = "toml"), allow(unused_imports))] extern crate elefren; pub use self::elefren::{Data, MastodonClient}; @@ -6,18 +8,22 @@ use std::{error::Error, io}; use self::elefren::{ apps::{App, Scopes}, - data::toml, Mastodon, Registration, }; +#[cfg(feature = "toml")] +use self::elefren::data::toml; + #[allow(dead_code)] +#[cfg(feature = "toml")] fn main() -> Result<(), Box> { register()?; Ok(()) } #[allow(dead_code)] +#[cfg(feature = "toml")] pub fn get_mastodon_data() -> Result> { if let Ok(data) = toml::from_file("mastodon-data.toml") { Ok(Mastodon::from(data)) @@ -26,6 +32,7 @@ pub fn get_mastodon_data() -> Result> { } } +#[cfg(feature = "toml")] pub fn register() -> Result> { let mut app = App::builder(); app.client_name("elefren-examples") @@ -48,6 +55,7 @@ pub fn register() -> Result> { Ok(mastodon) } +#[cfg(feature = "toml")] pub fn read_line(message: &str) -> Result> { println!("{}", message); @@ -56,3 +64,6 @@ pub fn read_line(message: &str) -> Result> { Ok(input.trim().to_string()) } + +#[cfg(not(feature = "toml"))] +fn main() { } diff --git a/examples/search.rs b/examples/search.rs index 00a7a76..4210c2a 100644 --- a/examples/search.rs +++ b/examples/search.rs @@ -1,8 +1,11 @@ +#![cfg_attr(not(feature = "toml"), allow(dead_code))] +#![cfg_attr(not(feature = "toml"), allow(unused_imports))] mod register; use register::MastodonClient; use std::error; +#[cfg(feature = "toml")] fn main() -> Result<(), Box> { let mastodon = register::get_mastodon_data()?; let input = register::read_line("Enter the term you'd like to search: ")?; @@ -12,3 +15,8 @@ fn main() -> Result<(), Box> { Ok(()) } + +#[cfg(not(feature = "toml"))] +fn main() { + println!("examples require the `toml` feature, run this command for this example:\n\ncargo run --example search --features toml\n"); +} diff --git a/examples/upload_photo.rs b/examples/upload_photo.rs index 4fa3790..b761a24 100644 --- a/examples/upload_photo.rs +++ b/examples/upload_photo.rs @@ -1,8 +1,11 @@ +#![cfg_attr(not(feature = "toml"), allow(dead_code))] +#![cfg_attr(not(feature = "toml"), allow(unused_imports))] mod register; use register::MastodonClient; use std::error; +#[cfg(feature = "toml")] fn main() -> Result<(), Box> { let mastodon = register::get_mastodon_data()?; let input = register::read_line("Enter the path to the photo you'd like to post: ")?; @@ -11,3 +14,8 @@ fn main() -> Result<(), Box> { Ok(()) } + +#[cfg(not(feature = "toml"))] +fn main() { + println!("examples require the `toml` feature, run this command for this example:\n\ncargo run --example upload_photo --features toml\n"); +}