Hemo-Morphic

Static dispatch in my bloodstream

[ rust ]

Laissez-Faire Errors

std::error

Errors in Rust are unique in that they can be handled in so many ways. This can be confusing and seem tedious at first, but there are advantages to being able to choose to panic! when an error is reached, or extending your own errors in such a way as to add context-specific information. Or you can choose to simply unwrap() when an error is reached. I am personally fond of creating errors using a custom enum and adding them as they are needed. Hence the title, laissez-faire errors.

post.explain_builders().build()

struct Builder

In my last post I started to explore using the builder pattern in Rust. In this post I want to go a bit more in depth about what a builder is and why it can be a versatile, idiomatic tool. They are especially helpful in situations where you might otherwise reach for patterns you are used to coming from another language and be wondering how to do the same in Rust without falling into an anti-pattern or battling the borrow checker.

Builders are a handy and idiomatic pattern to use when:

  • You want to use something like overloading (if you are coming from an Object Oriented Language)
  • would like to have default values that can be overwritten when needed at creation
  • Have a large number of possible inputs
  • Want optional add-ons
  • or anywhere you don't want a new(..) method that looks like a grocery list.

./mcp-example

cargo new mcp-server

I have been learning a bit about MCP and to better understand how the protocol can actually be used, specifically with Rust (and hopefully for Rust - but that's a story for another post!), I started with the Rust SDK.

init hemomorphic/

init hemomorphic/ --introduction

===========================================================================================
██╗  ██╗███████╗███╗   ███╗ ██████╗ ███╗   ███╗ ██████╗ ██████╗ ██████╗ ██╗  ██╗██╗ ██████╗
██║  ██║██╔════╝████╗ ████║██╔═══██╗████╗ ████║██╔═══██╗██╔══██╗██╔══██╗██║  ██║██║██╔════╝
███████║█████╗  ██╔████╔██║██║   ██║██╔████╔██║██║   ██║██████╔╝██████╔╝███████║██║██║     
██╔══██║██╔══╝  ██║╚██╔╝██║██║   ██║██║╚██╔╝██║██║   ██║██╔══██╗██╔═══╝ ██╔══██║██║██║     
██║  ██║███████╗██║ ╚═╝ ██║╚██████╔╝██║ ╚═╝ ██║╚██████╔╝██║  ██║██║     ██║  ██║██║╚██████╗
╚═╝  ╚═╝╚══════╝╚═╝     ╚═╝ ╚═════╝ ╚═╝     ╚═╝ ╚═════╝ ╚═╝  ╚═╝╚═╝     ╚═╝  ╚═╝╚═╝ ╚═════╝
===========================================================================================

Welcome to my blog. My name is Alex Blood. This is the initial blog post and marks the beginning of a blog I have been wanting to create for a long time.