Is there an algebraic approach to metric spaces? It is well known that most topological spaces can be studied via their algebra of continuous real-valued (or complex-valued) functions. For instance, in the setting of compact Hausdorff spaces, there is a complete dictionary between topological properties of the space $X$ and corresponding algebraic properties of the algebra $C(X)=C(X,\mathbb{R})$, and two such spaces $X$ and $Y$ are homeomorphic if and only if their algebras $C(X)$ and $C(Y)$ are isomorphic. A similar theory is available in the locally compact Hausdorff case, by replacing $C(X)$ with the algebra of real-valued functions on $X$ which vanish at infinity. Furthermore, these algebras are precisely all the commutative C*-algebras (at least if you take complex-valued functions). Thus if one wishes to study locally compact Hausdorff spaces, he might as well study commutative C*-algebras.
Is there an analogous algebraic approach to the theory of "nice" metric spaces (e.g. compact, locally compact, connected, etc.)? More specifically, is there a natural function space one can attach to every nice metric space which essentially contains all data about the metric space, up to isometry?
I'll welcome any references related to this question.
EDIT: Many of the answers referred me to Nik Weaver's (and others') theory of "Lipschitz algebras". I took a look at his book and while very interesting (and well written), it doesn't seem to be quite what I am looking for. More specifically, it seems that his constructions of Lipschitz algebras only characterize the metric space up to bi-Lipschitz equivalence (which he calls a quasi-isometry), while I'm looking for natural function spaces that would characterize the space up to isometry. His results in section 1.8 of the book show that two (pointed) complete metric spaces have isomorphic Lipschitz function algebras if and only if they are bi-Lipschitz equivalent, rather than isometric. He does have a characterization up to isometry (using a different Lipschitz algebra) for the class of metric spaces of diameter less than 2 (section 1.7) , but his reduction of a general metric space (say complete) to a metric space of diameter $\le 2$ is of course far from preserving isometries (rather preserving Lipschitz mappings).
So it seems that I am looking for a somewhat more "rigid" construction. Any ideas about that?
Thanks.
 A: I guess this is not the expected kind of answer, but you can study a metric space as a category, enriched over $\mathbb{R}_+$ - a monoidal category of non-negative real numbers (with $\infty$) with natural order and a single morphism $a\to b$ iff $a\geqslant b$. The monoidal structure on $\mathbb{R}_+$ is simply addition of real numbers $+$, considered as a symmetric enriched bifunctor. The original reference is "Metric spaces, generalized logic, and closed categories" by F.W. Lawvere. The category is associated in the most straightforward way: its objects are points of our metric space and $Hom(a,b)=dist(a,b)$. The law of morphism composition in a category is then precisely the triangle inequality. An enriched functor between such categories is a contracting mapping of metric spaces. Yoneda embedding embeds isometrically each metric space into a space of distance-decreasing functions equipped with sup-metric.
One should note that such generalized metric is not necessary symmetric and $>0$ for $a\ne b$, but in fact this isn't necessary to study it. One can always factor out zero-distance points and symmetrize the metric, and in fact this is a common procedure when one constructs new usual metric spaces.
A theory of Kan extensions becomes in this setting the following theorem: if $X \to Y$ is an isometric embedding, then any Lipschitz function on $X$ can be extended to $Y$ with the same Lipschitz constant. Among these there is the smallest and the largest one, corresponding to the left and right Kan extension.
Categorical limits become limits of sequences in metric space, and there is also a purely categorical formulation of Cauchy completeness condition. A category can be deduced from its category of $\mathbb{R}_+$-valued functors only up to equivalence - an equality of Cauchy completions. So complete metric spaces can be equivalently described by the metric spaces $\mathbb{R}^{X^{op}}_+$ of $\mathbb{R}_+$-valued contracting mappings on them. $\mathbb{R}_+$ has two natural monoidal structures: $+$ and $\times$. Both addition and multiplication of non-negative have a natural extension to bifunctors. They induce pointwisely two monoidal structures on $\mathbb{R}^{X^{op}}_+$, turning it into a semiring (no additive inverses). Thus I guess that you can take metric semiring of distance-decreasing functions as an algebraic description of a metric space. There are purely categorical conditions for a category to be equivalent to some category of functors (smallness conditions). They can be used to tell if our metric semiring is really a semiring of distance-decreasing functions on a metric space.
A: A very complete reference is the book "Lipschitz Algebras" by Nik Weaver. In there you will find various types of spaces of Lipschitz functions that can be associated to a metric space, and several results of the kind you are asking about.
From the book's introduction:

Thus, there is a robust duality
  between metric properties of $X$ and
  algebraic properties of $Lip_0(X)$.
  The set of weak* continuous
  homomorphisms from $Lip_0(X)$ into the
  scalars can be isometrically
  identified with the completion of $X$
  (Theorem 4.3.2); Lipschitz maps from
  $X$ into $Y$ correspond to weak*
  continuous  homomorphisms from
  $Lip_0(Y)$ into $Lip_0(X)$ (Corollary
  4.2.9); closed subsets of $X$ correspond to weak* closed ideals of
  $Lip_0(X)$ (Theorem 4.2.5); and 
  nonexpansive images of $X$ correspond
  to weak* closed, self-adjoint
  subalgebras of $Lip_0(X)$ (Theorem
  4.1.10).

A: I guess I'm late to the party, but here are a couple of points:

*

*Yes, an arbitrary complete pointed metric space $X$ with finite diameter is characterized up to isometry in terms of $Lip_0(X)$.  $X$ is naturally isometric to the set of weak* continuous homomorphisms from $Lip_0(X)$ into the scalars.  See Theorem 7.26 of the second edition of my book.


*In response to another comment, the restriction to diameter at most 2, for spaces without a distinguished base point, is natural.  For these spaces the Gelfand transform takes $X$ isometrically into the unit sphere of $Lip(X)^*$.  A metric space can isometrically embed in the unit sphere of a Banach space if and only if its diameter is at most 2.
A: An algebraic context for metric spaces--attractive to me--can be be provided by translation lattices, introduced (in the bounded, distributive case) by Irving Kaplansky, Lattices of continuous functions II, Amer. J. Math. 70 (1948), pp. 626-634; see also Włodzimierz Holsztyński, Lattices with real numbers as additive operators, Dissertationes Mathematicae LXII, Warszawa 1969, where the unbounded and non-distributive translation lattices are included (they all are called d-lattices there to stress the importance of the distance $d$).
A: The natural functions in this context are Lipschitz; e.g. functions $d_x(y)=d(x,y)$ determine an isometric embedding of a metric space $X$ to $L_\infty(X)$. For a noncommutative analogue see G.Kuperberg, N.Weaver, "A von Neumann algebra approach to quantum metrics", https://arxiv.org/abs/1005.0353
A: Marc Rieffel has studied a notion of `quantum' compact metric space that has its roots in the picture of unital C*-algebras as noncommutative compact Hausdorff spaces:  see http://arxiv.org/pdf/math/9906151v2 and http://arxiv.org/abs/math/0011063, for example. One should consider this answer as a supplement to the answers above citing the work of Nik Weaver  and Greg Kuperberg. 
Note: Rieffel uses the word 'quantum' in place of 'noncommutative' because the multiplicative structure doesn't really play a role. 
A: I believe that a framework for what you want has been spelled out by Marc Rieffel, as Jon Bannon has pointed out already.  He has several papers devoted to the subject of "quantum" metric spaces.  The paper Metrics on State Spaces is a good starting point, I think.  Section 8 is exactly what you should look at.  I will just write a few details here for those that are curious.
The point is that you consider not only the algebra of functions, but the additional data of the Lipschitz seminorm associated to the metric.  More precisely, if $(X,d)$ is a compact metric space, let $A = C_{\mathbb{R}}(X)$, and consider the (possibly $\infty$-valued) seminorm
$$  L(f) = \sup_{x \neq y} \frac{|f(x) - f(y)|}{d(x,y)}   $$
for $f \in A$.
Gelfand duality allows you to reconstruct the topological space $X$ from the commutative (real) $C^*$-algebra $A$; the Lipschitz seminorm $L$ contains the extra information of the metric.  In fact, it's not too  hard to show that for $x,y \in X$ we have
$$ d(x,y) = \sup \{  |f(x) - f(y)| : f \in A,  L(f) \le 1    \}.  $$
So the pair $(A,L)$ contains all the information about $(X,d)$.
Theorem 8.1 and Corollary 8.3 of the paper I mentioned characterize exactly which seminorms arise in this way.  I am obscuring some details about the conditions that $L$ needs to satisfy, but the most important property is that the Lipschitz seminorm satisfies the "lattice inequality"
$$ L(f \vee g) \le L(f) \vee L(g),  $$
where $\vee$ means maximum on both sides of the inequality.
The point is that if you have a seminorm $L$ on $C_{\mathbb{R}}(X)$ which satisfies the lattice inequality (I am ignoring finiteness assumptions and some technical conditions), the formula above allows you to recover the metric, and the technical assumptions ensure that this metric induces the right topology on $X$.
This recovers the metric up to isometry and seems quite canonical; is this what you had in mind by a "rigid" construction?
