Skip to content

Commit 7e77315

Browse files
docs(pre-compute,post-compute): improve rustdoc examples
1 parent 47224cd commit 7e77315

File tree

9 files changed

+43
-129
lines changed

9 files changed

+43
-129
lines changed

post-compute/src/api/worker_api.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use serde::Serialize;
2323
///
2424
/// # Example
2525
///
26-
/// ```
26+
/// ```rust
2727
/// use tee_worker_post_compute::{
2828
/// api::worker_api::ExitMessage,
2929
/// compute::errors::ReplicateStatusCause,
@@ -49,7 +49,7 @@ impl<'a> From<&'a ReplicateStatusCause> for ExitMessage<'a> {
4949
///
5050
/// # Example
5151
///
52-
/// ```
52+
/// ```rust
5353
/// use tee_worker_post_compute::api::worker_api::WorkerApiClient;
5454
///
5555
/// let client = WorkerApiClient::new("http://worker:13100");
@@ -80,7 +80,7 @@ impl WorkerApiClient {
8080
///
8181
/// # Example
8282
///
83-
/// ```
83+
/// ```rust
8484
/// use tee_worker_post_compute::api::worker_api::WorkerApiClient;
8585
///
8686
/// let client = WorkerApiClient::from_env();
@@ -119,7 +119,7 @@ impl WorkerApiClient {
119119
///
120120
/// # Example
121121
///
122-
/// ```
122+
/// ```rust
123123
/// use tee_worker_post_compute::{
124124
/// api::worker_api::{ExitMessage, WorkerApiClient},
125125
/// compute::errors::ReplicateStatusCause,
@@ -189,7 +189,7 @@ impl WorkerApiClient {
189189
///
190190
/// # Example
191191
///
192-
/// ```
192+
/// ```rust
193193
/// use tee_worker_post_compute::{
194194
/// api::worker_api::WorkerApiClient,
195195
/// compute::computed_file::ComputedFile,

post-compute/src/compute/computed_file.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ pub struct ComputedFile {
6868
///
6969
/// # Example
7070
///
71-
/// ```
71+
/// ```rust
7272
/// use tee_worker_post_compute::compute::computed_file::read_computed_file;
7373
///
7474
/// match read_computed_file("0x123456789abcdef", "/iexec_out") {
@@ -153,7 +153,7 @@ pub fn read_computed_file(
153153
///
154154
/// # Example
155155
///
156-
/// ```
156+
/// ```rust
157157
/// use tee_worker_post_compute::compute::computed_file::{
158158
/// build_result_digest_in_computed_file,
159159
/// ComputedFile
@@ -235,7 +235,7 @@ pub fn build_result_digest_in_computed_file(
235235
///
236236
/// # Example
237237
///
238-
/// ```
238+
/// ```rust
239239
/// use tee_worker_post_compute::compute::computed_file::{
240240
/// sign_computed_file,
241241
/// ComputedFile

post-compute/src/compute/utils/result_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use std::{
3030
///
3131
/// # Example
3232
///
33-
/// ```
33+
/// ```rust
3434
/// use tee_worker_post_compute::compute::{computed_file::ComputedFile, utils::result_utils::compute_web3_result_digest};
3535
///
3636
/// let computed_file = ComputedFile {
@@ -93,7 +93,7 @@ pub fn compute_web3_result_digest(computed_file: &ComputedFile) -> String {
9393
///
9494
/// # Example
9595
///
96-
/// ```
96+
/// ```rust
9797
/// use tee_worker_post_compute::compute::{computed_file::ComputedFile, utils::result_utils::compute_web2_result_digest};
9898
///
9999
/// let computed_file = ComputedFile {
@@ -225,7 +225,7 @@ pub fn sha256_file(file_path: &Path) -> String {
225225
///
226226
/// # Example
227227
///
228-
/// ```
228+
/// ```rust
229229
/// use std::path::Path;
230230
/// use tee_worker_post_compute::compute::utils::result_utils::get_file_tree_sha256;
231231
///

pre-compute/src/api/worker_api.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use serde::Serialize;
2222
///
2323
/// # Example
2424
///
25-
/// ```
25+
/// ```rust
2626
/// use tee_worker_pre_compute::api::worker_api::ExitMessage;
2727
/// use tee_worker_pre_compute::compute::errors::ReplicateStatusCause;
2828
///
@@ -46,7 +46,7 @@ impl<'a> From<&'a ReplicateStatusCause> for ExitMessage<'a> {
4646
///
4747
/// # Example
4848
///
49-
/// ```
49+
/// ```rust
5050
/// use tee_worker_pre_compute::api::worker_api::WorkerApiClient;
5151
///
5252
/// let client = WorkerApiClient::new("http://worker:13100");
@@ -77,7 +77,7 @@ impl WorkerApiClient {
7777
///
7878
/// # Example
7979
///
80-
/// ```
80+
/// ```rust
8181
/// use tee_worker_pre_compute::api::worker_api::WorkerApiClient;
8282
///
8383
/// let client = WorkerApiClient::from_env();
@@ -116,7 +116,7 @@ impl WorkerApiClient {
116116
///
117117
/// # Example
118118
///
119-
/// ```
119+
/// ```rust
120120
/// use tee_worker_pre_compute::api::worker_api::{ExitMessage, WorkerApiClient};
121121
/// use tee_worker_pre_compute::compute::errors::ReplicateStatusCause;
122122
///

pre-compute/src/compute/app_runner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub enum ExitMode {
2929
///
3030
/// # Example
3131
///
32-
/// ```
32+
/// ```rust
3333
/// use tee_worker_pre_compute::compute::app_runner::start_with_app;
3434
/// use tee_worker_pre_compute::compute::pre_compute_app::PreComputeApp;
3535
///
@@ -86,7 +86,7 @@ pub fn start_with_app<A: PreComputeAppTrait>(
8686
///
8787
/// # Example
8888
///
89-
/// ```
89+
/// ```rust
9090
/// use tee_worker_pre_compute::compute::app_runner::start;
9191
///
9292
/// let exit_code = start();

pre-compute/src/compute/pre_compute_app.rs

Lines changed: 19 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,25 @@ impl PreComputeApp {
4949
}
5050

5151
impl PreComputeAppTrait for PreComputeApp {
52+
/// Runs the complete pre-compute pipeline.
53+
///
54+
/// This method orchestrates the entire pre-compute process:
55+
/// 1. Reads configuration arguments
56+
/// 2. Validates the output folder exists
57+
/// 3. Downloads and decrypts the dataset (if required)
58+
/// 4. Downloads all input files
59+
///
60+
/// # Returns
61+
///
62+
/// - `Ok(())` if all operations completed successfully
63+
/// - `Err(ReplicateStatusCause)` if any step failed
64+
///
65+
/// # Example
66+
///
67+
/// ```rust
68+
/// let mut app = PreComputeApp::new("task_id".to_string());
69+
/// app.run()?;
70+
/// ```
5271
fn run(&mut self) -> Result<(), ReplicateStatusCause> {
5372
self.pre_compute_args = PreComputeArgs::read_args()?;
5473
self.check_output_folder()?;
@@ -61,23 +80,6 @@ impl PreComputeAppTrait for PreComputeApp {
6180
Ok(())
6281
}
6382

64-
/// Checks whether the output folder specified in `pre_compute_args` exists.
65-
///
66-
/// # Returns
67-
///
68-
/// - `Ok(())` if the output directory (`output_dir`) exists.
69-
/// - `Err(ReplicateStatusCause::PreComputeOutputFolderNotFound)` if the directory does not exist,
70-
/// or if `pre_compute_args` is missing.
71-
///
72-
/// # Example
73-
///
74-
/// ```
75-
/// use tee_worker_pre_compute::compute::pre_compute_app::{PreComputeApp, PreComputeAppTrait};
76-
///
77-
/// let mut pre_compute_app = PreComputeApp::new("0x123456789abcdef".to_string());
78-
///
79-
/// pre_compute_app.check_output_folder();
80-
/// ```
8183
fn check_output_folder(&self) -> Result<(), ReplicateStatusCause> {
8284
let output_dir: &str = &self.pre_compute_args.output_dir;
8385
let chain_task_id: &str = &self.chain_task_id;
@@ -93,31 +95,6 @@ impl PreComputeAppTrait for PreComputeApp {
9395
Err(ReplicateStatusCause::PreComputeOutputFolderNotFound)
9496
}
9597

96-
/// Downloads the input files listed in `pre_compute_args.input_files` to the specified `output_dir`.
97-
///
98-
/// Each URL is hashed (SHA-256) to generate a unique local filename.
99-
/// If any download fails, the function returns an error.
100-
///
101-
/// # Returns
102-
///
103-
/// - `Ok(())` if all files are downloaded successfully.
104-
/// - `Err(ReplicateStatusCause::PreComputeInputFileDownloadFailed)` if any file fails to download.
105-
///
106-
/// # Panics
107-
///
108-
/// This function panics if:
109-
/// - `pre_compute_args` is `None`.
110-
/// - `chain_task_id` is `None`.
111-
///
112-
/// # Example
113-
///
114-
/// ```
115-
/// use tee_worker_pre_compute::compute::pre_compute_app::{PreComputeApp, PreComputeAppTrait};
116-
///
117-
/// let mut pre_compute_app = PreComputeApp::new("0x123456789abcdef".to_string());
118-
///
119-
/// pre_compute_app.download_input_files().unwrap();
120-
/// ```
12198
fn download_input_files(&self) -> Result<(), ReplicateStatusCause> {
12299
let args = &self.pre_compute_args;
123100
let chain_task_id: &str = &self.chain_task_id;
@@ -133,23 +110,6 @@ impl PreComputeAppTrait for PreComputeApp {
133110
Ok(())
134111
}
135112

136-
/// Downloads the encrypted dataset file from a URL or IPFS multi-address, and verifies its checksum.
137-
///
138-
/// # Returns
139-
///
140-
/// * `Ok(Vec<u8>)` containing the dataset's encrypted content if download and verification succeed.
141-
/// * `Err(ReplicateStatusCause::PreComputeDatasetDownloadFailed)` if the download fails or inputs are missing.
142-
/// * `Err(ReplicateStatusCause::PreComputeInvalidDatasetChecksum)` if checksum validation fails.
143-
///
144-
/// # Example
145-
///
146-
/// ```
147-
/// use tee_worker_pre_compute::compute::pre_compute_app::{PreComputeApp, PreComputeAppTrait};
148-
///
149-
/// let mut app = PreComputeApp::new("0x123456789abcdef".to_string());
150-
///
151-
/// app.download_encrypted_dataset();
152-
/// ```
153113
fn download_encrypted_dataset(&self) -> Result<Vec<u8>, ReplicateStatusCause> {
154114
let args = &self.pre_compute_args;
155115
let chain_task_id = &self.chain_task_id;
@@ -192,30 +152,6 @@ impl PreComputeAppTrait for PreComputeApp {
192152
Ok(encrypted_content)
193153
}
194154

195-
/// Decrypts the provided encrypted dataset bytes using AES-CBC.
196-
///
197-
/// The first 16 bytes of `encrypted_content` are treated as the IV.
198-
/// The rest is the ciphertext. The decryption key is decoded from a Base64 string.
199-
///
200-
/// # Arguments
201-
///
202-
/// * `encrypted_content` - Full encrypted dataset, including the IV prefix.
203-
///
204-
/// # Returns
205-
///
206-
/// * `Ok(Vec<u8>)` containing the plaintext dataset if decryption succeeds.
207-
/// * `Err(ReplicateStatusCause::PreComputeDatasetDecryptionFailed)` if the key is missing, decoding fails, or decryption fails.
208-
///
209-
/// # Example
210-
///
211-
/// ```
212-
/// use tee_worker_pre_compute::compute::pre_compute_app::{PreComputeApp, PreComputeAppTrait};
213-
///
214-
/// let mut app = PreComputeApp::new("0x123456789abcdef".to_string());
215-
///
216-
/// let encrypted = vec![/* ... */];
217-
/// let decrypted = app.decrypt_dataset(&encrypted);
218-
/// ```
219155
fn decrypt_dataset(&self, encrypted_content: &[u8]) -> Result<Vec<u8>, ReplicateStatusCause> {
220156
let base64_key: &str = &self.pre_compute_args.encrypted_dataset_base64_key;
221157

@@ -236,29 +172,6 @@ impl PreComputeAppTrait for PreComputeApp {
236172
.map_err(|_| ReplicateStatusCause::PreComputeDatasetDecryptionFailed)
237173
}
238174

239-
/// Saves the decrypted (plain) dataset to disk in the configured output directory.
240-
///
241-
/// The output filename is taken from `pre_compute_args.plain_dataset_filename`.
242-
///
243-
/// # Arguments
244-
///
245-
/// * `plain_dataset` - The dataset content to write to a file.
246-
///
247-
/// # Returns
248-
///
249-
/// * `Ok(())` if the file is successfully saved.
250-
/// * `Err(ReplicateStatusCause::PreComputeSavingPlainDatasetFailed)` if the path is invalid or write fails.
251-
///
252-
/// # Example
253-
///
254-
/// ```
255-
/// use tee_worker_pre_compute::compute::pre_compute_app::{PreComputeApp, PreComputeAppTrait};
256-
///
257-
/// let mut app = PreComputeApp::new("0x123456789abcdef".to_string());
258-
///
259-
/// let plain_data = vec![/* ... */];
260-
/// app.save_plain_dataset_file(&plain_data);
261-
/// ```
262175
fn save_plain_dataset_file(&self, plain_dataset: &[u8]) -> Result<(), ReplicateStatusCause> {
263176
let chain_task_id: &str = &self.chain_task_id;
264177
let args = &self.pre_compute_args;

pre-compute/src/compute/pre_compute_args.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ impl PreComputeArgs {
4444
/// - Missing input file URLs
4545
///
4646
/// # Example
47-
/// ```
47+
///
48+
/// ```rust
4849
/// use tee_worker_pre_compute::compute::pre_compute_args::PreComputeArgs;
4950
///
5051
/// // Typically called with task ID from execution context

pre-compute/src/compute/signer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use alloy_signer_local::PrivateKeySigner;
2828
///
2929
/// # Example
3030
///
31-
/// ```
31+
/// ```rust
3232
/// use tee_worker_pre_compute::compute::signer::sign_enclave_challenge;
3333
///
3434
/// let message_hash = "0x5cd0e9c5180dd35e2b8285d0db4ded193a9b4be6fbfab90cbadccecab130acad";
@@ -83,7 +83,7 @@ pub fn sign_enclave_challenge(
8383
///
8484
/// # Example
8585
///
86-
/// ```
86+
/// ```rust
8787
/// use tee_worker_pre_compute::compute::signer::get_challenge;
8888
///
8989
/// // Assuming the necessary environment variables are set:

pre-compute/src/compute/utils/file_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::path::{Path, PathBuf};
2121
///
2222
/// # Example
2323
///
24-
/// ```
24+
/// ```rust
2525
/// use std::path::PathBuf;
2626
/// use tee_worker_pre_compute::compute::utils::file_utils::write_file;
2727
///
@@ -69,7 +69,7 @@ pub fn write_file(content: &[u8], file_path: &Path, context: &str) -> Result<(),
6969
///
7070
/// # Example
7171
///
72-
/// ```
72+
/// ```rust
7373
/// use tee_worker_pre_compute::compute::utils::file_utils::download_file;
7474
///
7575
/// if let Some(path) = download_file("https://iex.ec/file.txt", "/tmp", "iexec.txt") {
@@ -151,7 +151,7 @@ pub fn download_file(url: &str, parent_dir: &str, filename: &str) -> Option<Path
151151
///
152152
/// # Example
153153
///
154-
/// ```
154+
/// ```rust
155155
/// use tee_worker_pre_compute::compute::utils::file_utils::download_from_url;
156156
/// if let Some(bytes) = download_from_url("https://httpbin.org/json/test.json") {
157157
/// println!("Downloaded {} bytes", bytes.len());

0 commit comments

Comments
 (0)