pub trait Profiles: MaybeSend + 'static {
// Required methods
fn watch(&self, events: Events<ProfileEvent>);
fn follow(&self, id: ProfileId, follow: bool, reply: Reply<()>);
}Expand description
The host’s profiles and follow relations. The host keeps the account, decides who may follow
whom and what a profile shows; the library shows what the host pushes and sends the user’s
follow and unfollow requests through follow. It never changes
Profile::followed itself.
Methods are called on the UI thread and must return at once; answer and push from any thread, runtime or browser task.
use std::sync::Mutex;
use egui_charts::data::Reply;
use egui_charts::services::{Events, Profile, ProfileEvent, ProfileId, Profiles};
/// One profile that accepts every follow request. A real host asks its server.
#[derive(Default)]
struct Local(Mutex<Option<Events<ProfileEvent>>>);
impl Profiles for Local {
fn watch(&self, events: Events<ProfileEvent>) {
events.push(ProfileEvent::Upsert(Profile::new(ProfileId("1".into()), "Ada")));
*self.0.lock().unwrap() = Some(events);
}
fn follow(&self, id: ProfileId, follow: bool, reply: Reply<()>) {
if let Some(events) = &*self.0.lock().unwrap() {
let mut profile = Profile::new(id, "Ada");
profile.followed = follow;
events.push(ProfileEvent::Upsert(profile));
}
reply.send(Ok(()));
}
}Required Methods§
Sourcefn watch(&self, events: Events<ProfileEvent>)
fn watch(&self, events: Events<ProfileEvent>)
Pushes the profiles the user can see, then every change until events is inactive. Called
when the directory starts and again after a lagged stream, each time with a new stream that
starts from no profiles. The stream takes at most 10,000 pushes between two frames.
Sourcefn follow(&self, id: ProfileId, follow: bool, reply: Reply<()>)
fn follow(&self, id: ProfileId, follow: bool, reply: Reply<()>)
Follows id when follow is true, otherwise unfollows it. Push the profile with its new
Profile::followed as ProfileEvent::Upsert first, then answer Ok once the relation
changed, or with a FeedError the user can read if the host
refused. Authorization belongs to the host: refuse a request the signed-in user may not
make.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".