Migrate your app to Rust, one piece at a time, checked against the original's recorded behavior at every step. TypeScript/JavaScript, Python, C, Go, Ruby, Java, Kotlin, PHP, C# and PowerShell
fromtypingimportOptionalclassStack:"""A bounded stack of strings."""def__init__(self,capacity:int=8):ifcapacity<1:raiseValueError("capacity must be at least 1")self._items:list[str]=[]self._capacity=capacitydefpush(self,item:str)->int:iflen(self._items)>=self._capacity:raiseOverflowError("stack is full")self._items.append(item)returnlen(self._items)defpop(self)->Optional[str]:returnself._items.pop()ifself._itemselseNonedefpeek(self)->Optional[str]:returnself._items[-1]ifself._itemselseNonedefsize(self)->int:returnlen(self._items)