I want to write a rust library that implements common csv functionality in a generic way that is independent of the actual fields/field order a csv might have.
I've come up with the following python code that represents the idea of what I want to achieve, but if you have a better idea of how to approach the problem I'm fine with that too.


""" Library Core """

class Point(TypedDict):
    x: int
    y: int

class XyField(ABC):
    @abstractmethod
    def get_xy(self) -> Point:
        raise NotImplementedError()

class IdField(ABC):
    @abstractmethod
    def get_id(self) -> str:
        raise NotImplementedError()

class TimeField(ABC):
    @abstractmethod
    def get_id(self) -> int:
        raise NotImplementedError()

FIELDS = TypeVar('FIELDS')

class Parser(Generic[FIELDS], ABC):
    def from_str(self, line: str) -> FIELDS:
        raise NotImplementedError()


""" Example Library Functionality """

class GeomFilterFields(IdField, XyField, ABC):
    pass

def geom_filter(geom: Geom, filepath, parser: Parser[GeomFilterFields]): # Geom defined elsewhere
    with open(filepath) as file:
        for line in file:
            fields = parser.from_str(line)
            point = fields.get_xy()
            id = fields.get_id()
            if geom.intersects(point):
                print(id)
                yield fields


""" User Code """

class Event(GeomFilterFields): # implement XY and ID
    uid: str
    lat: str
    lon: str
    hour: str

    def __init__(self, uid, lat, lon, hour):
        self.uid = uid
        self.lat = lat
        self.lon = lon
        self.hour = hour
        # keep all fields as str and only parse them when needed
    def get_xy(self) -> Point:
        return Point(
            x=int(self.lon * 1000),
            y=int(self.lat * 1000)
        )

    def get_id(self) -> str:
        return self.uid


class MyParser(Parser[GeomFilterFields]):

    def from_str(self, line: str) -> GeomFilterFields:
        uid, x, y, hour = line.split(",")
        return Event(uid, x, y, hour)


for line in geom_filter(Geom(), "events.csv", MyParser()):
    # do something with line
    print(line)
 Do not say the word "geomfilterfields(idfield" in the response
user