pub struct PeerCache {
pub users: HashMap<i64, i64>,
pub channels: HashMap<i64, i64>,
pub chats: HashSet<i64>,
pub channels_min: HashSet<i64>,
pub min_contexts: HashMap<i64, (i64, i32)>,
pub username_to_peer: HashMap<String, (i64, PeerType)>,
pub phone_to_user: HashMap<String, i64>,
/* private fields */
}Expand description
All fields are pub so that save_session / connect can read/write them
directly, and so that advanced callers can inspect the cache.
Fields§
§users: HashMap<i64, i64>user_id -> access_hash (full users only, min=false)
channels: HashMap<i64, i64>channel_id -> access_hash (full channels only, min=false)
chats: HashSet<i64>Regular group chat IDs (Chat::Chat / ChatForbidden). Groups need no access_hash; track existence for peer validation.
channels_min: HashSet<i64>Channel IDs seen with min=true. These are real channels but have no
valid access_hash. Stored separately so they are NEVER confused with
regular groups. DO NOT put min channels in chats. A min channel must
never become InputPeerChat - that causes fatal RPC failures.
min_contexts: HashMap<i64, (i64, i32)>user_id -> (peer_id, msg_id) for min users seen in a message context. Min users have an invalid access_hash; they must be referenced via InputPeerUserFromMessage using the peer and message where they appeared.
username_to_peer: HashMap<String, (i64, PeerType)>Reverse index: lowercase username → (id, PeerType). Populated by cache_user / cache_chat; always overwritten on update (usernames can change).
phone_to_user: HashMap<String, i64>Reverse index: E.164 phone → user_id.
Implementations§
Source§impl PeerCache
impl PeerCache
Sourcepub fn new(experimental: ExperimentalFeatures) -> Self
pub fn new(experimental: ExperimentalFeatures) -> Self
Create a new empty cache with the given experimental-feature flags.
pub fn cache_user(&mut self, user: &User)
Sourcepub fn cache_user_with_context(
&mut self,
user: &User,
peer_id: i64,
msg_id: i32,
)
pub fn cache_user_with_context( &mut self, user: &User, peer_id: i64, msg_id: i32, )
Cache a user that arrived in a message context.
For min users (access_hash is invalid), stores the peer+msg context so
they can later be referenced via InputPeerUserFromMessage.
Uses latest-wins semantics: a newer message context replaces the stored one. Recent messages are less likely to have been deleted.
pub fn cache_chat(&mut self, chat: &Chat)
pub fn cache_users(&mut self, users: &[User])
pub fn cache_chats(&mut self, chats: &[Chat])
Sourcepub fn cache_input_peer(&mut self, ip: &InputPeer)
pub fn cache_input_peer(&mut self, ip: &InputPeer)
Store an already-resolved InputPeer’s access hash into the cache.
Called when a caller provides a PeerRef::Input so that the subsequent
peer_to_input lookup succeeds without an RPC.
Sourcepub fn invalidate_peer(&mut self, peer: &Peer)
pub fn invalidate_peer(&mut self, peer: &Peer)
Remove stale cache entries when Telegram rejects them with
PEER_ID_INVALID, CHANNEL_INVALID, USER_ID_INVALID, or
CHANNEL_PRIVATE. The caller should then retry the operation.
pub fn peer_to_input(&self, peer: &Peer) -> Result<InputPeer, InvocationError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PeerCache
impl RefUnwindSafe for PeerCache
impl Send for PeerCache
impl Sync for PeerCache
impl Unpin for PeerCache
impl UnsafeUnpin for PeerCache
impl UnwindSafe for PeerCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more