-
Notifications
You must be signed in to change notification settings - Fork 253
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
Rust SDK: introduce MsgSender
builder-like interface for logging data
#1037
Conversation
527eb79
to
6c1b5fc
Compare
6c1b5fc
to
060dc01
Compare
MsgSender
builder-like interface for logging data
/// .map_err(Into::into) | ||
/// } | ||
/// ``` | ||
pub struct MsgSender { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe MsgBuilder
, or LogBuilder
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It used to be called that way, but really it cannot give you back a message, all it can do is send one (more than one actually because the message is likely to get splitted into parts internally)
|
||
/// All the different timestamps for this message. | ||
/// | ||
/// The logging time is automatically inserted during creation ([`Self::new`]). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want log time set with new()
, or send()
? What if they create a builder and hang on to it for a while before calling send()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no go solution besides logging and/or making it configurable; but really in practice this won't matter for the foreseeable future as there's really not any reason to hold on to one of these as I can think of.
} | ||
} | ||
|
||
fn bundle_from_iter<'a, C: SerializableComponent>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use ComponentBundle::try_from
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have such an impl and I cannot define it due to orphan rules 😞
I'll leave the commented out impl there for future reference.
|
||
/// Returns the number of _instances_ for a given `row` in the bundle, i.e. the length of a | ||
/// specific row within the bundle. | ||
pub fn nb_instances(&self, row: usize) -> Option<usize> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit of a style bikeshed, but I find num_instances
a lot more clear, and my wild guess, with zero data to back it up, is that it is less likely to confuse others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make a note to unify our code styles here at some point (currently conducting a twitter poll to gauge popular opinion)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah I never actually thought about it until now; it's a very french thing actually 🥲
I'll keep it as-is for now because it's consistent with how I've written it everywhere in the store, but I definitely think this warrants a big s/nb_/num_
PR.
.iter() | ||
.map(|bundle| bundle.name) | ||
.all_unique(), | ||
msg.components.iter().map(|bundle| bundle.name).all_unique(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a bit weird to refer both to msg.components
and to its alias bundles
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TL;DR: this is all in dire need of a terminology pass; at the moment I don't know of any good solution here.
msg.components.iter().map(|components| ...)
is technically correct but plain confusing.msg.components.iter().map(|component| ...)
looks like you'd expect but is plain wrong.msg.components.iter().map(|bundle| ...)
looks awful but at least it makes you look twice, which you should because there's more going on than meets the eye.
The root of the issue is that msg.components
is too vague: this is in fact an array (component types) of arrays (rows) of actual components (instances/columns).
I guess we'll clean all of this when we implement support for batch insertions.
// TODO(cmc): kind & insert_id need to somehow propagate through the span system. | ||
self.insert_id += 1; | ||
|
||
let MsgBundle { | ||
msg_id, | ||
entity_path: ent_path, | ||
time_point, | ||
components, | ||
} = bundle; | ||
components: bundles, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't components
a more descriptive name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, see above.
examples/raw_mesh/src/main.rs
Outdated
/// If specified, connects and sends the logged data to a remote Rerun viewer. | ||
#[clap(long)] | ||
#[allow(clippy::option_option)] | ||
addr: Option<Option<String>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha, that's… interesting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙃 I guess I should rename it to connect
though, that would flow more naturally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, agree
MsgSender
, a builder-like API for easily & safely logging components in Rustraw_mesh
example to use these new APIsSerializableComponent
traitnb_components
,nb_rows
&nb_instances
helpers where requiredSummary listing of important TODOs for my later self when I'll start opening issues: