Skip to content

Instantly share code, notes, and snippets.

@bahrom04
Created December 27, 2025 14:24
Show Gist options
  • Select an option

  • Save bahrom04/317da584721a1e9f93351ab53c891b94 to your computer and use it in GitHub Desktop.

Select an option

Save bahrom04/317da584721a1e9f93351ab53c891b94 to your computer and use it in GitHub Desktop.
Python ABC va Rust trait
from abc import ABC, abstractmethod
class Animal(ABC):
def __init__(self, name):
self.name = name
@abstractmethod
def speak(self):
print("hayvon buni gapirdi: ", self.name)
class Sheep(Animal):
def __init__(self, name):
super().__init__(name)
def speak(self):
super().speak()
print("Try programiz.pro")
qoy = Sheep("aaahhhh")
qoy.speak()
# hayvon = Animal("aaahhhh")
# hayvon.speak()
trait Animal {
fn new(name: &'static str, naked: bool) -> Self;
fn name(&self) -> &'static str;
fn speak(&self) {
println!("Hello, world!. Qoʻyni ismi {}", self.name());
}
}
struct Sheep {
naked: bool,
name: &'static str,
}
impl Animal for Sheep {
fn new(name: &'static str, naked: bool) -> Sheep {
Sheep { naked, name }
}
fn name(&self) -> &'static str {
self.name
}
}
fn main() {
let qoʻy: Sheep = Animal::new("qoʻy", false);
qoʻy.speak();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment