Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collector: Refresh example in doccomment #3292

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 43 additions & 33 deletions collector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,56 @@
//!
//! # Examples
//!
//! Initialize an instance of [`Collector`].
//!
//! ```no_run
//! use janus_collector::{AuthenticationToken, Collector};
//! use janus_core::{hpke::generate_hpke_config_and_private_key};
//! use janus_messages::{
//! Duration, HpkeAeadId, HpkeConfig, HpkeConfigId, HpkeKdfId, HpkeKemId, Interval, TaskId,
//! Time, Query,
//! };
//! use std::{fs::File, str::FromStr};
//!
//! use janus_collector::{Collector, PrivateCollectorCredential};
//! use janus_messages::{Duration, FixedSizeQuery, Interval, Query, TaskId, Time};
//! use prio::vdaf::prio3::Prio3;
//! use rand::random;
//! use url::Url;
//!
//! # async fn run() {
//! // Supply DAP task parameters.
//! let task_id = random();
//! let hpke_keypair = janus_core::hpke::generate_hpke_config_and_private_key(
//! HpkeConfigId::from(0),
//! HpkeKemId::X25519HkdfSha256,
//! HpkeKdfId::HkdfSha256,
//! HpkeAeadId::Aes128Gcm,
//! ).unwrap();
//! let task_id = TaskId::from_str("[your DAP task ID here]").unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend leaving this un-indented, since the function's opening and closing braces won't appear in the final output. (It's just present to allow us to use .await in this context)

//!
//! let collector_credential: PrivateCollectorCredential =
//! serde_json::from_reader(File::open("[path to JSON encoded collector credential]").unwrap())
//! .unwrap();
//!
//! let leader_url =
//! Url::from_str("[absolute URI to the DAP leader, e.g. https://leader.dap.example.com/]")
//! .unwrap();
//!
//! // Supply a VDAF implementation, corresponding to this task.
//! let vdaf = Prio3::new_count(2).unwrap();
//!
//! let collector = Collector::new(
//! task_id,
//! leader_url,
//! collector_credential.authentication_token(),
//! collector_credential.hpke_keypair(),
//! vdaf,
//! )
//! .unwrap();
//!
//! // If this is a time interval task, specify the time interval over which the aggregation
//! // should be calculated.
//! let interval = Interval::new(
//! Time::from_seconds_since_epoch(1_656_000_000),
//! Duration::from_seconds(3600),
//! )
//! .unwrap();
//!
//! // Supply a VDAF implementation, corresponding to this task.
//! let vdaf = Prio3::new_count(2).unwrap();
//! let collector = Collector::new(
//! task_id,
//! "https://example.com/dap/".parse().unwrap(),
//! AuthenticationToken::new_bearer_token_from_string("Y29sbGVjdG9yIHRva2Vu").unwrap(),
//! hpke_keypair,
//! vdaf,
//! )
//! .unwrap();
//! // Make the requests and retrieve the aggregated statistic.
//! let aggregation_result = collector
//! .collect(Query::new_time_interval(interval), &())
//! .await
//! .unwrap();
//!
//! // Specify the time interval over which the aggregation should be calculated.
//! let interval = Interval::new(
//! Time::from_seconds_since_epoch(1_656_000_000),
//! Duration::from_seconds(3600),
//! )
//! .unwrap();
//! // Make the requests and retrieve the aggregated statistic.
//! let aggregation_result = collector.collect(Query::new_time_interval(interval), &()).await.unwrap();
//! // Or if this is a fixed size task, make a fixed size query.
//! let query = Query::new_fixed_size(FixedSizeQuery::CurrentBatch);
//! let aggregation_result = collector.collect(query, &()).await.unwrap();
//! # }
//! ```

Expand Down
Loading