Skip to main content

PeerExt

Trait PeerExt 

Source
pub trait PeerExt {
    // Required method
    fn bare_id(&self) -> i64;
}
Expand description

Convenience extension for tl::enums::Peer: extract the numeric ID without writing a match every time.

§Example

use ferogram::PeerExt;
use ferogram::OptionPeerExt;
use ferogram::tl;

// Instead of:
// let id = match peer { Peer::User(u) => u.user_id, Peer::Chat(c) => c.chat_id, ... };
// Just write:
let id = peer.bare_id();

// Works great with sender_id() / peer_id() on IncomingMessage:
if let Some(id) = msg.sender_id().bare_id() {
    println!("sender: {id}");
}
// Chat ID:
if let Some(id) = msg.peer_id().bare_id() {
    println!("chat: {id}");
}

Required Methods§

Source

fn bare_id(&self) -> i64

Returns the raw Telegram ID for any peer variant.

  • Peer::Useruser_id
  • Peer::Chatchat_id (basic group)
  • Peer::Channelchannel_id (supergroup / broadcast channel)

Note: these are native Telegram IDs, not Bot-API-encoded ones. A channel with native ID 1234567890 would be -1001234567890 in the Bot API. Use crate::peer_ref encoding if you need the Bot-API form.

Implementations on Foreign Types§

Source§

impl PeerExt for Peer

Source§

fn bare_id(&self) -> i64

Implementors§