Press "Enter" to skip to content

How to extract Rust function signatures from .rs file using sed – one-liner

To extract function signatures from .rs file you can use following one-liner with sed:

sed -n -e '/pub fn/,/)/p' file.rs

Sample output:

  pub fn chip(&self) -> Chip {
    pub fn device_info(&mut self) -> Result<DeviceInfo, Error> {
        let chip = self.chip();
    pub fn load_elf_to_ram(
        &mut self,
        elf_data: &[u8],
        mut progress: Option<&mut dyn ProgressCallbacks>,
    ) -> Result<(), Error> {