Skip to content

Commit fea2a31

Browse files
committed
review and stuff
1 parent 9d836e3 commit fea2a31

File tree

6 files changed

+26
-56
lines changed

6 files changed

+26
-56
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/re_data_source/src/data_loader/loader_external.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ pub fn iter_external_loaders() -> impl ExactSizeIterator<Item = std::path::PathB
6060
/// The external loaders are expected to log rrd data to their standard output.
6161
///
6262
/// Refer to our `external_data_loader` example for more information.
63-
pub struct ExternalDataLoader;
63+
pub struct ExternalLoader;
6464

65-
impl crate::DataLoader for ExternalDataLoader {
65+
impl crate::DataLoader for ExternalLoader {
6666
#[inline]
6767
fn name(&self) -> String {
6868
"rerun.data_loaders.External".into()

crates/re_data_source/src/data_loader/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ use re_log_types::{ArrowMsg, DataRow, LogMsg};
2222
/// [There are plans to make this generic over any URI](https://github.com/rerun-io/rerun/issues/4525).
2323
///
2424
/// Rerun comes with a few [`DataLoader`]s by default:
25-
/// - [`RrdLoader`] for [Rerun files]
25+
/// - [`RrdLoader`] for [Rerun files].
2626
/// - [`ArchetypeLoader`] for:
2727
/// - [3D models]
2828
/// - [Images]
2929
/// - [Point clouds]
3030
/// - [Text files]
31-
/// - [`DirectoryLoader`] for recursively loading folders
31+
/// - [`DirectoryLoader`] for recursively loading folders.
32+
/// - `ExternalLoader`, which looks for user-defined data loaders in $PATH.
3233
///
3334
/// ## Execution
3435
///
@@ -210,7 +211,7 @@ static BUILTIN_LOADERS: Lazy<Vec<Arc<dyn DataLoader>>> = Lazy::new(|| {
210211
Arc::new(ArchetypeLoader),
211212
Arc::new(DirectoryLoader),
212213
#[cfg(not(target_arch = "wasm32"))]
213-
Arc::new(ExternalDataLoader),
214+
Arc::new(ExternalLoader),
214215
]
215216
});
216217

@@ -237,5 +238,5 @@ pub use self::loader_rrd::RrdLoader;
237238
pub(crate) use self::loader_external::EXTERNAL_LOADER_PATHS;
238239
#[cfg(not(target_arch = "wasm32"))]
239240
pub use self::loader_external::{
240-
iter_external_loaders, ExternalDataLoader, EXTERNAL_DATA_LOADER_PREFIX,
241+
iter_external_loaders, ExternalLoader, EXTERNAL_DATA_LOADER_PREFIX,
241242
};

crates/re_data_source/src/load_file.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,16 @@ pub(crate) fn load(
146146
contents: Option<std::borrow::Cow<'_, [u8]>>,
147147
) -> Result<std::sync::mpsc::Receiver<LoadedData>, DataLoaderError> {
148148
#[cfg(target_arch = "wasm32")]
149-
let no_external_loaders = true;
149+
let has_external_loaders = false;
150150
#[cfg(not(target_arch = "wasm32"))]
151-
let no_external_loaders = crate::data_loader::EXTERNAL_LOADER_PATHS.is_empty();
151+
let has_external_loaders = !crate::data_loader::EXTERNAL_LOADER_PATHS.is_empty();
152152

153153
let extension = extension(path);
154154
let is_builtin = is_associated_with_builtin_loader(path, is_dir);
155155

156156
// If there are no external loaders registered (which is always the case on wasm) and we don't
157157
// have a builtin loader for it, then we know for a fact that we won't be able to load it.
158-
if !is_builtin && no_external_loaders {
158+
if !is_builtin && !has_external_loaders {
159159
return if extension.is_empty() {
160160
Err(anyhow::anyhow!("files without extensions (file.XXX) are not supported").into())
161161
} else {

examples/rust/external_data_loader/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ publish = false
99
[dependencies]
1010
rerun = { path = "../../../crates/rerun" }
1111

12-
pico-args = { version = "0.5.0", features = ["eq-separator"] }
12+
argh = "0.1"

examples/rust/external_data_loader/src/main.rs

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,6 @@
11
//! Example of an external data-loader executable plugin for the Rerun Viewer.
22
3-
use rerun::MediaType;
4-
5-
const USAGE: &str = "
6-
This is an example executable data-loader plugin for the Rerun Viewer.
7-
8-
It will log Rust source code files as markdown documents.
9-
To try it out, install it in your $PATH (`cargo install --path . -f`), then open a Rust source file with Rerun (`rerun file.rs`).
10-
11-
USAGE:
12-
rerun-loader-rust-file [OPTIONS] FILEPATH
13-
14-
FLAGS:
15-
-h, --help Prints help information
16-
17-
OPTIONS:
18-
--recording-id RECORDING_ID ID of the shared recording
19-
20-
ARGS:
21-
<FILEPATH>
22-
";
23-
24-
#[allow(clippy::exit)]
25-
fn usage() -> ! {
26-
eprintln!("{USAGE}");
27-
std::process::exit(1);
28-
}
3+
use rerun::{external::re_data_source::extension, MediaType};
294

305
// The Rerun Viewer will always pass these two pieces of information:
316
// 1. The path to be loaded, as a positional arg.
@@ -34,33 +9,27 @@ fn usage() -> ! {
349
// It is up to you whether you make use of that shared recording ID or not.
3510
// If you use it, the data will end up in the same recording as all other plugins interested in
3611
// that file, otherwise you can just create a dedicated recording for it. Or both.
12+
13+
/// This is an example executable data-loader plugin for the Rerun Viewer.
14+
///
15+
/// It will log Rust source code files as markdown documents.
16+
/// To try it out, install it in your $PATH (`cargo install --path . -f`), then open
17+
/// Rust source file with Rerun (`rerun file.rs`).
18+
#[derive(argh::FromArgs)]
3719
struct Args {
20+
#[argh(positional)]
3821
filepath: std::path::PathBuf,
39-
recording_id: Option<String>,
40-
}
4122

42-
impl Args {
43-
fn from_env() -> Result<Self, pico_args::Error> {
44-
let mut pargs = pico_args::Arguments::from_env();
45-
Ok(Self {
46-
filepath: pargs.free_from_str()?,
47-
recording_id: pargs.opt_value_from_str("--recording-id")?,
48-
})
49-
}
23+
/// optional ID of the shared recording
24+
#[argh(option)]
25+
recording_id: Option<String>,
5026
}
5127

5228
fn main() -> Result<(), Box<dyn std::error::Error>> {
53-
let Ok(args) = Args::from_env() else {
54-
usage();
55-
};
29+
let args: Args = argh::from_env();
5630

5731
let is_file = args.filepath.is_file();
58-
let is_rust_file = args
59-
.filepath
60-
.extension()
61-
.unwrap_or_default()
62-
.to_ascii_lowercase()
63-
== "rs";
32+
let is_rust_file = extension(&args.filepath) == "rs";
6433

6534
// We're not interested: just exit silently.
6635
// Don't return an error, as that would show up to the end user in the Rerun Viewer!

0 commit comments

Comments
 (0)