How is the Public and Pair Trait used in the public function 'get_from_seed'

use sp_core::{Pair, Public, sr25519};

/// Generate a crypto pair from seed.
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
    TPublic::Pair::from_string(&format!("//{}", seed), None)
        .expect("static values are valid; qed")

in the function signature why does TPublic(generic type) perform what seems like type annotation? And I do not understand the ruturn type.
The function body is also quite confusing

The left: right syntax means different things in different contexts, and it is not a type annotation in this case. Instead, it is a trait bound. You can tell the difference by whether the left-hand-side is a variable or a type. If it's a value, then it's a type annotation, but if the left-hand-side is a type, then it is a trait bound.

The meaning of the trait bound is that TPublic must be a type that implements the Public trait. This trait is a super-trait of CryptoType, which has an associated type called Pair, which must implement the trait Pair of the same name. When you write TPublic::Pair, this means "whatever type the associated type Pair is set to in the impl CryptoType for TPublic block".

The syntax in the return type says that it returns whatever the associated type Public is set to in the impl Pair for TPublic::Pair block. The <... as Pair> part makes it explicit that you are talking about the type Public from the impl Pair for ... block rather than an type Public from an impl SomeOtherTraitThanPair for ... block.

thanks for responding, but i still don't get it :weary: