pub struct ApiKey(/* private fields */);
Implementations§
Source§impl ApiKey
impl ApiKey
Sourcepub fn new(key: impl Into<String>) -> Self
pub fn new(key: impl Into<String>) -> Self
Examples found in repository?
examples/playlist.rs (line 12)
9fn main() -> Result<(), Error> {
10 futures::executor::block_on(async {
11 // take api key from enviroment variable
12 let key = ApiKey::new(&env::var("YT_API_KEY").expect("YT_API_KEY env-var not found"));
13
14 // create the PlaylistItems struct for some playlist ID
15 let result = PlaylistItems::new(key)
16 .playlist_id("PLVvjrrRCBy2JSHf9tGxGKJ-bYAN_uDCUL")
17 .max_results(50)
18 .await?;
19
20 for item in result.items {
21 println!(
22 "https://youtube.com/watch?v={}",
23 item.snippet.resource_id.video_id
24 );
25 }
26
27 Ok(())
28 })
29}
More examples
examples/complex_search.rs (line 12)
9fn main() -> Result<(), Error> {
10 futures::executor::block_on(async {
11 // take api key from enviroment variable
12 let key = ApiKey::new(&env::var("YT_API_KEY").expect("YT_API_KEY env-var not found"));
13
14 // create the SearchList struct for the query "rust lang"
15 let result = SearchList::new(key)
16 .q("rust lang")
17 .max_results(1)
18 .item_type(ItemType::Video)
19 .location(VideoLocation::new(40.73061, -73.93524))
20 .location_radius("100km")
21 .video_embeddable()
22 .await?;
23
24 // outputs the video_id of the first search result
25 println!(
26 "Title: \"{}\"",
27 result.items[0].snippet.title.as_ref().unwrap()
28 );
29 println!(
30 "https://youtube.com/watch?v={}",
31 result.items[0].id.video_id.as_ref().unwrap()
32 );
33
34 Ok(())
35 })
36}
examples/search.rs (line 12)
9fn main() -> Result<(), Error> {
10 futures::executor::block_on(async {
11 // take api key from enviroment variable
12 let key = ApiKey::new(&env::var("YT_API_KEY").expect("YT_API_KEY env-var not found"));
13
14 // create the SearchList struct for the query "rust lang"
15 let result = SearchList::new(key)
16 .q("rust lang")
17 .item_type(ItemType::Video)
18 .await?;
19
20 // outputs the title of the first search result
21 println!(
22 "Title: \"{}\"",
23 result.items[0].snippet.title.as_ref().unwrap()
24 );
25 // outputs the video id of the first search result
26 println!(
27 "https://youtube.com/watch?v={}",
28 result.items[0].id.video_id.as_ref().unwrap()
29 );
30
31 println!(
32 "Default thumbnail: {}",
33 result.items[0]
34 .snippet
35 .thumbnails
36 .as_ref()
37 .unwrap()
38 .default
39 .as_ref()
40 .unwrap()
41 .url
42 );
43
44 Ok(())
45 })
46}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ApiKey
impl RefUnwindSafe for ApiKey
impl Send for ApiKey
impl Sync for ApiKey
impl Unpin for ApiKey
impl UnwindSafe for ApiKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more