-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "log_file" | ||
version = "0.14.0-alpha.2" | ||
edition = "2021" | ||
rust-version = "1.74" | ||
license = "MIT OR Apache-2.0" | ||
publish = false | ||
|
||
[dependencies] | ||
rerun = { path = "../../../crates/rerun", features = ["web_viewer", "clap"] } | ||
|
||
anyhow = "1.0" | ||
clap = { version = "4.0", features = ["derive"] } | ||
glam = "0.22" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!--[metadata] | ||
title = "Log file example" | ||
--> | ||
|
||
Demonstrates how to log any file from the SDK using the [`DataLoader`](https://www.rerun.io/docs/howto/open-any-file) machinery. | ||
|
||
Usage: | ||
```bash | ||
cargo run -p log_file -- examples/assets | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//! Demonstrates how to log any file from the SDK using the `DataLoader` machinery. | ||
//! | ||
//! See <https://www.rerun.io/docs/howto/open-any-file> for more information. | ||
//! | ||
//! Usage: | ||
//! ``` | ||
//! cargo run -p log_file -- examples/assets | ||
//! ``` | ||
|
||
use rerun::external::re_log; | ||
|
||
#[derive(Debug, clap::Parser)] | ||
#[clap(author, version, about)] | ||
struct Args { | ||
#[command(flatten)] | ||
rerun: rerun::clap::RerunArgs, | ||
|
||
// Log the contents of the file directly (files only -- not supported by external loaders). | ||
#[clap(long, default_value = "false")] | ||
from_contents: bool, | ||
|
||
/// The filepaths to be loaded and logged. | ||
filepaths: Vec<std::path::PathBuf>, | ||
} | ||
|
||
fn main() -> anyhow::Result<()> { | ||
re_log::setup_logging(); | ||
|
||
use clap::Parser as _; | ||
let args = Args::parse(); | ||
|
||
let (rec, _serve_guard) = args.rerun.init("rerun_example_log_file")?; | ||
run(&rec, &args)?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn run(rec: &rerun::RecordingStream, args: &Args) -> anyhow::Result<()> { | ||
for filepath in &args.filepaths { | ||
let filepath = filepath.as_path(); | ||
|
||
if !args.from_contents { | ||
// Either log the file using its path… | ||
rec.log_file_from_path(filepath)?; | ||
} else { | ||
// …or using its contents if you already have them loaded for some reason. | ||
if filepath.is_file() { | ||
let contents = std::fs::read(filepath)?; | ||
rec.log_file_from_contents(filepath, std::borrow::Cow::Borrowed(&contents))?; | ||
} | ||
} | ||
} | ||
|
||
// TODO(cmc): This is required because the way we handle RecordingStream clones in subtly | ||
// broken. That's outside the scope of this PR, I'll fix this in a follow-up. | ||
rec.disconnect(); | ||
|
||
Ok(()) | ||
} |